Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
chore(package): resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mjancarik committed Sep 20, 2019
2 parents d675dc1 + 37231b9 commit 1a6393d
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 50 deletions.
37 changes: 26 additions & 11 deletions Bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ export default class Bootstrap {
_initSettings() {
let currentApplicationSettings = {};

let plugins = this._config.plugins.concat([this._config]);
let plugins = this._config.plugins.concat([
{ name: ObjectContainer.APP_BINDING_STATE, module: this._config }
]);

plugins
.filter(plugin => typeof plugin.initSettings === 'function')
.filter(plugin => typeof plugin.module.initSettings === 'function')
.forEach(plugin => {
let allPluginSettings = plugin.initSettings(
let allPluginSettings = plugin.module.initSettings(
ns,
this._oc,
this._config.settings
Expand All @@ -87,7 +89,7 @@ export default class Bootstrap {
this._config.settings.$Env
);

$Helper.assignRecursively(
$Helper.assignRecursivelyWithTracking(plugin.name)(
currentApplicationSettings,
environmentPluginSetting
);
Expand Down Expand Up @@ -125,17 +127,30 @@ export default class Bootstrap {
*/
_bindDependencies() {
this._oc.setBindingState(ObjectContainer.IMA_BINDING_STATE);
this._config.initBindIma(ns, this._oc, this._config.bind);
this._config.initBindIma(
ns,
this._oc,
this._config.bind,
ObjectContainer.IMA_BINDING_STATE
);

this._oc.setBindingState(ObjectContainer.PLUGIN_BINDING_STATE);
this._config.plugins
.filter(plugin => typeof plugin.initBind === 'function')
.filter(plugin => typeof plugin.module.initBind === 'function')
.forEach(plugin => {
plugin.initBind(ns, this._oc, this._config.bind);
this._oc.setBindingState(
ObjectContainer.PLUGIN_BINDING_STATE,
plugin.name
);
plugin.module.initBind(ns, this._oc, this._config.bind, plugin.name);
});

this._oc.setBindingState(ObjectContainer.APP_BINDING_STATE);
this._config.initBindApp(ns, this._oc, this._config.bind);
this._config.initBindApp(
ns,
this._oc,
this._config.bind,
ObjectContainer.APP_BINDING_STATE
);
}

/**
Expand All @@ -153,9 +168,9 @@ export default class Bootstrap {
this._config.initServicesIma(ns, this._oc, this._config.services);

this._config.plugins
.filter(plugin => typeof plugin.initServices === 'function')
.filter(plugin => typeof plugin.module.initServices === 'function')
.forEach(plugin => {
plugin.initServices(ns, this._oc, this._config.services);
plugin.module.initServices(ns, this._oc, this._config.services);
});

this._config.initServicesApp(ns, this._oc, this._config.services);
Expand Down
42 changes: 39 additions & 3 deletions ObjectContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ export default class ObjectContainer {
* @type {?string}
*/
this._bindingState = null;

/**
* The current plugin binding to OC.
*
* The {@linkcode setBindingState()} method may be called for changing
* object container binding state only by the bootstrap script.
*
* @type {?string}
*/
this._bindingPlugin = null;
}

/**
Expand Down Expand Up @@ -418,15 +428,17 @@ export default class ObjectContainer {
clear() {
this._entries.clear();
this._bindingState = null;
this._bindingPlugin = null;

return this;
}

/**
*
* @param {?string} bindingState
* @param {?string} bindingPluginName
*/
setBindingState(bindingState) {
setBindingState(bindingState, bindingPluginName = null) {
if (this._bindingState === ObjectContainer.APP_BINDING_STATE) {
throw new Error(
`ima.ObjectContainer:setBindingState The setBindingState() ` +
Expand All @@ -436,6 +448,10 @@ export default class ObjectContainer {
}

this._bindingState = bindingState;
this._bindingPlugin =
bindingState === ObjectContainer.PLUGIN_BINDING_STATE
? bindingPluginName
: null;
}

/**
Expand Down Expand Up @@ -521,7 +537,13 @@ export default class ObjectContainer {
dependencies = classConstructor.$dependencies;
}

return new Entry(classConstructor, dependencies, options);
let referrer = this._bindingState;

if (this._bindingState === ObjectContainer.PLUGIN_BINDING_STATE) {
referrer = this._bindingPlugin;
}

return new Entry(classConstructor, dependencies, referrer, options);
}

/**
Expand Down Expand Up @@ -699,9 +721,11 @@ class Entry {
* class constructor or constant value getter.
* @param {*[]} [dependencies=[]] The dependencies to pass into the
* constructor function.
* @param {?string} referrer Reference to part of application that created
* this entry.
* @param {?{ writeable: boolean }} [options] The Entry options.
*/
constructor(classConstructor, dependencies, options) {
constructor(classConstructor, dependencies, referrer, options) {
/**
* The constructor of the class represented by this entry, or the
* getter of the value of the constant represented by this entry.
Expand All @@ -726,6 +750,14 @@ class Entry {
writeable: true
};

/**
* Reference to part of application that created
* this entry.
*
* @type {string}
*/
this._referrer = referrer;

/**
* Dependencies of the class constructor of the class represented by
* this entry.
Expand Down Expand Up @@ -767,6 +799,10 @@ class Entry {
return this._dependencies;
}

get referrer() {
return this._referrer;
}

get writeable() {
return this._options.writeable;
}
Expand Down
29 changes: 20 additions & 9 deletions __tests__/BootstrapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Bootstrap', () => {
settings: {
$Env: 'prod'
},
plugins: [plugin],
plugins: [{ name: 'test-plugin', module: plugin }],
initSettings: () => environments,
initBindIma: () => {},
initBindApp: () => {},
Expand Down Expand Up @@ -104,7 +104,8 @@ describe('Bootstrap', () => {
bootstrap._bindDependencies();

expect(objectContainer.setBindingState).toHaveBeenCalledWith(
ObjectContainer.PLUGIN_BINDING_STATE
ObjectContainer.PLUGIN_BINDING_STATE,
'test-plugin'
);
});

Expand All @@ -127,8 +128,10 @@ describe('Bootstrap', () => {
namespace,
objectContainer,
{
$Env: 'prod'
}
$Env: 'prod',
__meta__: {}
},
'ima'
);
});

Expand All @@ -137,9 +140,15 @@ describe('Bootstrap', () => {

bootstrap._bindDependencies();

expect(plugin.initBind).toHaveBeenCalledWith(namespace, objectContainer, {
$Env: 'prod'
});
expect(plugin.initBind).toHaveBeenCalledWith(
namespace,
objectContainer,
{
$Env: 'prod',
__meta__: {}
},
'test-plugin'
);
});

it('should bind app', () => {
Expand All @@ -151,8 +160,10 @@ describe('Bootstrap', () => {
namespace,
objectContainer,
{
$Env: 'prod'
}
$Env: 'prod',
__meta__: {}
},
'app'
);
});
});
Expand Down
8 changes: 7 additions & 1 deletion config/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ClientPageManager from '../page/manager/ClientPageManager';
import PageManager from '../page/manager/PageManager';
import ServerPageManager from '../page/manager/ServerPageManager';
import ClientPageRenderer from '../page/renderer/ClientPageRenderer';
import ComponentUtils from '../page/renderer/ComponentUtils';
import PageRenderer from '../page/renderer/PageRenderer';
import PageRendererFactory from '../page/renderer/PageRendererFactory';
import ServerPageRenderer from '../page/renderer/ServerPageRenderer';
Expand Down Expand Up @@ -143,9 +144,14 @@ export default (ns, oc, config) => {
//Page
oc.provide(PageStateManager, PageStateManagerImpl);
oc.bind('$PageStateManager', PageStateManager);

oc.inject(PageFactory, [oc]);
oc.bind('$PageFactory', PageFactory);
oc.inject(PageRendererFactory, [oc, '$React']);

oc.inject(ComponentUtils, [oc]);
oc.bind('$ComponentUtils', ComponentUtils);

oc.inject(PageRendererFactory, [ComponentUtils, '$React']);
oc.bind('$PageRendererFactory', PageRendererFactory);

if (oc.get(Window).isClient()) {
Expand Down
43 changes: 25 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@
"Javascript"
],
"author": "Miroslav Jancarik <miroslav.jancarik@firma.seznam.cz>",
"contributors": [{
"name": "Martin Urban",
"email": "martin.urban@firma.seznam.cz"
}, {
"name": "Martin Jurča",
"email": "martin.jurca@firma.seznam.cz"
}, {
"name": "Ondřej Baše",
"email": "ondrej.base@firma.seznam.cz"
}],
"contributors": [
{
"name": "Martin Urban",
"email": "martin.urban@firma.seznam.cz"
},
{
"name": "Martin Jurča",
"email": "martin.jurca@firma.seznam.cz"
},
{
"name": "Ondřej Baše",
"email": "ondrej.base@firma.seznam.cz"
}
],
"repository": {
"type": "git",
"url": "https://github.com/seznam/IMA.js-core.git"
Expand All @@ -50,7 +54,7 @@
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
"@commitlint/cli": "^8.0.0",
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.0.0",
"@fortawesome/fontawesome-free": "^5.10.2",
"@size-limit/preset-big-lib": "^2.1.5",
Expand Down Expand Up @@ -142,11 +146,14 @@
],
"testRegex": "(/__tests__/.*|(\\.|/)(Spec))\\.jsx?$"
},
"size-limit": [{
"limit": "1 s",
"path": "dist/ima.client.cjs.js"
}, {
"limit": "1 s",
"path": "dist/ima.client.esm.js"
}]
"size-limit": [
{
"limit": "1 s",
"path": "dist/ima.client.cjs.js"
},
{
"limit": "1 s",
"path": "dist/ima.client.esm.js"
}
]
}
Loading

0 comments on commit 1a6393d

Please sign in to comment.