Comparing version 5.5.0 to 5.6.0
@@ -131,3 +131,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _this = this; | ||
this.options = __assign({ name: null, parentApp: null, providers: [], providerNames: defaultProviderNames, | ||
this.options = __assign({ name: null, methods: {}, parentApp: null, providers: [], providerNames: defaultProviderNames, | ||
// lifecycle callbacks | ||
@@ -142,2 +142,12 @@ // tslint:disable-next-line:no-empty | ||
} | ||
// expose methods as class properties | ||
Object.keys(this.options.methods).forEach(function (methodName) { | ||
var method = _this.options.methods[methodName]; | ||
if (typeof method === 'function') { | ||
if (_this[methodName] !== undefined) { | ||
throw new Error("Cannot overwrite app's `" + methodName + "` property or method with options method."); | ||
} | ||
_this[methodName] = method.bind(_this); | ||
} | ||
}); | ||
// children - create Observable if root | ||
@@ -144,0 +154,0 @@ this._appsCollection = []; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("lodash/merge"),require("lodash/find"),require("lodash/findIndex"),require("lodash/get"),require("lodash/omit"),require("rxjs/BehaviorSubject"),require("rxjs/observable/of"),require("rxjs/operators/concatMap"),require("rxjs/operators/find"),require("rxjs/operators/first"),require("rxjs/operators/map")):"function"==typeof define&&define.amd?define(["lodash/merge","lodash/find","lodash/findIndex","lodash/get","lodash/omit","rxjs/BehaviorSubject","rxjs/observable/of","rxjs/operators/concatMap","rxjs/operators/find","rxjs/operators/first","rxjs/operators/map"],t):"object"==typeof exports?exports.Frint=t(require("lodash/merge"),require("lodash/find"),require("lodash/findIndex"),require("lodash/get"),require("lodash/omit"),require("rxjs/BehaviorSubject"),require("rxjs/observable/of"),require("rxjs/operators/concatMap"),require("rxjs/operators/find"),require("rxjs/operators/first"),require("rxjs/operators/map")):e.Frint=t(e._.merge,e._.find,e._.findIndex,e._.get,e._.omit,e.Rx,e.Rx.Observable,e.Rx.operators,e.Rx.operators,e.Rx.operators,e.Rx.operators)}("undefined"!=typeof self?self:this,function(e,t,r,n,o,i,s,a,p,u,c){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";function n(e,t,r){if(void 0===e&&(e=null),void 0===t&&(t=null),void 0===r&&(r=!1),!r||!e&&!t)return"default";var n="";return e&&(n=e),t&&(n=e+"_"+t),n}var o=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e};Object.defineProperty(t,"__esModule",{value:!0});var i=r(4),s=r(7),a=r(8),p=r(9),u=r(10),c=r(11),f=r(12),l=r(13),d=r(14),h=r(15),v=r(16),y={component:"component",container:"container",store:"store",app:"app",parentApp:"parentApp",rootApp:"rootApp",region:"region"},g=function(){function e(e){var t=this;if(this.options=o({name:null,parentApp:null,providers:[],providerNames:y,initialize:function(){},beforeDestroy:function(){}},e),!this.options.name)throw new Error("Must provide `name` in options");this._appsCollection=[],this._apps$=new c.BehaviorSubject(this._appsCollection);var r=i.createContainer([{name:this.options.providerNames.app,useDefinedValue:this},{name:this.options.providerNames.parentApp,useDefinedValue:this.getParentApp()},{name:this.options.providerNames.rootApp,useDefinedValue:this.getRootApp()}],{containerName:this.options.providerNames.container});this.container=i.resolveContainer(r),this._registerRootProviders(),this.options.providers.forEach(function(e){t.container.register(e)}),this.options.initialize.bind(this)()}return e.prototype.getContainer=function(){return this.container},e.prototype.getRootApp=function(){var e=this.getParentApps();return 0===e.length?this:e.pop()},e.prototype.getParentApp=function(){return this.options[this.options.providerNames.parentApp]||null},e.prototype.getParentApps=function(){function e(t,r){void 0===r&&(r=[]);var n=t.getParentApp();return n?(r.push(n),e(n,r)):r}return e(this)},e.prototype.getOption=function(e){return p(this.options,e)},e.prototype.getName=function(){return this.getOption("name")},e.prototype.getProviders=function(){return this.options.providers},e.prototype.getProvider=function(e){return s(this.options.providers,function(t){return t.name===e})},e.prototype.get=function(e){var t=this.container.get(e);return void 0!==t?t:null},e.prototype.getApps$=function(e){return void 0===e&&(e=null),e?this._apps$.pipe(v.map(function(t){return t.filter(function(t){return t.regions.indexOf(e)>-1})})):this._apps$},e.prototype.registerApp=function(t,r){void 0===t&&(t=e),void 0===r&&(r={});var n=o({multi:!1},r);if(void 0!==n.name&&Object.defineProperty(t,"frintAppName",{value:n.name,configurable:!0}),-1!==a(this._appsCollection,function(e){return e.name===t.frintAppName}))throw new Error("App '"+t.frintAppName+"' has been already registered before.");this._appsCollection.push(o({},n,{name:t.frintAppName,appClass:t,instances:{},regions:n.regions||[]})),!1===n.multi&&this.instantiateApp(t.frintAppName),this._apps$.next(this._appsCollection)},e.prototype.hasAppInstance=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var n=this.getAppInstance(e,t,r);return!(!n||void 0===n)},e.prototype.getAppInstance=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var o=a(this._appsCollection,function(t){return t.name===e});if(-1===o)return null;var i=this._appsCollection[o],s=n(t,r,i.multi),p=i.instances[s];return p&&void 0!==p?p:null},e.prototype.getAppOnceAvailable$=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var o=this.getRootApp(),i=o.getAppInstance(e,t,r);return i?f.of(i):o._apps$.pipe(l.concatMap(function(e){return e}),d.find(function(t){return t.name===e}),v.map(function(e){var o=n(t,r,e.multi);return e.instances[o]}),h.first())},e.prototype.instantiateApp=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var i=a(this._appsCollection,function(t){return t.appClass.frintAppName===e});if(-1===i)throw new Error("No app found with name '"+e+"'.");var s=this._appsCollection[i],p=n(t,r,s.multi);return this._appsCollection[i].instances[p]=new s.appClass(o({},u(s,["AppClass","instances"]),{name:s.appClass.frintAppName,parentApp:this})),this._appsCollection[i].instances[p]},e.prototype.destroyApp=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var o=a(this._appsCollection,function(t){return!(!t||!t.appClass)&&t.appClass.frintAppName===e});if(-1===o)throw new Error("No app found with name '"+e+"'.");var i=this._appsCollection[o],s=n(t,r,i.multi);if(void 0===this._appsCollection[o].instances[s])throw new Error("No instance with key '"+s+"' found for app with name '"+e+"'.");this._appsCollection[o].instances[s].beforeDestroy(),delete this._appsCollection[o].instances[s]},e.prototype.beforeDestroy=function(){return this.options.beforeDestroy.bind(this)()},e.prototype._registerRootProviders=function(){var e=this,t=this.getParentApps();0!==t.length&&t.reverse().forEach(function(t){t.getProviders().forEach(function(r){if(r.cascade){var n=Object.assign({},u(r,["useClass","useValue","useFactory"]));return r.scoped?"useValue"in r?void e.container.register(o({},n,{useValue:t.get(r.name)})):"useClass"in r?void e.container.register(o({},n,{useClass:r.useClass})):void("useFactory"in r&&e.container.register(o({},n,{useFactory:r.useFactory}))):void e.container.register(o({},n,{useValue:t.get(r.name)}))}})})},e}();t.App=g},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2);t.createApp=n.default;var o=r(0);t.App=o.App},function(e,t,r){"use strict";function n(e,t){var r=s({},e,t);return["initialize","beforeDestroy"].forEach(function(n){"function"==typeof e[n]&&"function"==typeof t[n]&&(r[n]=function(){e[n].call(this),t[n].call(this)})}),r}function o(e){var t=function(t){function r(r){return void 0===r&&(r={}),t.call(this,n(e,r))||this}return i(r,t),r}(a.App);return void 0!==e.name&&Object.defineProperty(t,"frintAppName",{value:e.name,configurable:!0}),t}var i=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(t,"__esModule",{value:!0});var s=r(3),a=r(0);t.default=o},function(t,r){t.exports=e},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(5),i=n(o),s=r(6),a=n(s);t.default={createContainer:i.default,resolveContainer:a.default},e.exports=t.default},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=a({containerName:"container"},t);return function(){function t(){var o=this;n(this,t),this.registry={},Object.defineProperty(this.registry,r.containerName,{get:function(){return o}}),e.forEach(function(e){o.register(e)})}return s(t,[{key:"getDeps",value:function(e){var t=this,r=e.name,n={};return Array.isArray(e.deps)?e.deps.forEach(function(e){if(!(e in t.registry))throw new Error("For provider '"+r+"', dependency '"+e+"' is not available yet.");n[e]=t.registry[e]}):"object"===i(e.deps)&&Object.keys(e.deps).forEach(function(o){if(!(o in t.registry))throw new Error("For provider '"+r+"', dependency '"+o+"' is not available yet.");var i=e.deps[o];n[i]=t.registry[o]}),n}},{key:"register",value:function(e){if("string"!=typeof e.name)throw new Error("Provider has no 'name' key.");var t=e.name;if("useValue"in e)this.registry[t]=e.useValue;else if("useFactory"in e)this.registry[t]=e.useFactory(this.getDeps(e));else if("useClass"in e)this.registry[t]=new e.useClass(this.getDeps(e));else{if(!("useDefinedValue"in e))throw new Error("No value given for '"+t+"' provider.");Object.defineProperty(this.registry,t,{get:function(){return e.useDefinedValue}})}}},{key:"get",value:function(e){return this.registry[e]}}]),t}()}Object.defineProperty(t,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.default=o,e.exports=t.default},function(e,t,r){"use strict";function n(e){return new e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n,e.exports=t.default},function(e,r){e.exports=t},function(e,t){e.exports=r},function(e,t){e.exports=n},function(e,t){e.exports=o},function(e,t){e.exports=i},function(e,t){e.exports=s},function(e,t){e.exports=a},function(e,t){e.exports=p},function(e,t){e.exports=u},function(e,t){e.exports=c}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("lodash/merge"),require("lodash/find"),require("lodash/findIndex"),require("lodash/get"),require("lodash/omit"),require("rxjs/BehaviorSubject"),require("rxjs/observable/of"),require("rxjs/operators/concatMap"),require("rxjs/operators/find"),require("rxjs/operators/first"),require("rxjs/operators/map")):"function"==typeof define&&define.amd?define(["lodash/merge","lodash/find","lodash/findIndex","lodash/get","lodash/omit","rxjs/BehaviorSubject","rxjs/observable/of","rxjs/operators/concatMap","rxjs/operators/find","rxjs/operators/first","rxjs/operators/map"],t):"object"==typeof exports?exports.Frint=t(require("lodash/merge"),require("lodash/find"),require("lodash/findIndex"),require("lodash/get"),require("lodash/omit"),require("rxjs/BehaviorSubject"),require("rxjs/observable/of"),require("rxjs/operators/concatMap"),require("rxjs/operators/find"),require("rxjs/operators/first"),require("rxjs/operators/map")):e.Frint=t(e._.merge,e._.find,e._.findIndex,e._.get,e._.omit,e.Rx,e.Rx.Observable,e.Rx.operators,e.Rx.operators,e.Rx.operators,e.Rx.operators)}("undefined"!=typeof self?self:this,function(e,t,r,n,o,i,s,p,a,u,c){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";function n(e,t,r){if(void 0===e&&(e=null),void 0===t&&(t=null),void 0===r&&(r=!1),!r||!e&&!t)return"default";var n="";return e&&(n=e),t&&(n=e+"_"+t),n}var o=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e};Object.defineProperty(t,"__esModule",{value:!0});var i=r(4),s=r(7),p=r(8),a=r(9),u=r(10),c=r(11),f=r(12),l=r(13),d=r(14),h=r(15),v=r(16),y={component:"component",container:"container",store:"store",app:"app",parentApp:"parentApp",rootApp:"rootApp",region:"region"},m=function(){function e(e){var t=this;if(this.options=o({name:null,methods:{},parentApp:null,providers:[],providerNames:y,initialize:function(){},beforeDestroy:function(){}},e),!this.options.name)throw new Error("Must provide `name` in options");Object.keys(this.options.methods).forEach(function(e){var r=t.options.methods[e];if("function"==typeof r){if(void 0!==t[e])throw new Error("Cannot overwrite app's `"+e+"` property or method with options method.");t[e]=r.bind(t)}}),this._appsCollection=[],this._apps$=new c.BehaviorSubject(this._appsCollection);var r=i.createContainer([{name:this.options.providerNames.app,useDefinedValue:this},{name:this.options.providerNames.parentApp,useDefinedValue:this.getParentApp()},{name:this.options.providerNames.rootApp,useDefinedValue:this.getRootApp()}],{containerName:this.options.providerNames.container});this.container=i.resolveContainer(r),this._registerRootProviders(),this.options.providers.forEach(function(e){t.container.register(e)}),this.options.initialize.bind(this)()}return e.prototype.getContainer=function(){return this.container},e.prototype.getRootApp=function(){var e=this.getParentApps();return 0===e.length?this:e.pop()},e.prototype.getParentApp=function(){return this.options[this.options.providerNames.parentApp]||null},e.prototype.getParentApps=function(){function e(t,r){void 0===r&&(r=[]);var n=t.getParentApp();return n?(r.push(n),e(n,r)):r}return e(this)},e.prototype.getOption=function(e){return a(this.options,e)},e.prototype.getName=function(){return this.getOption("name")},e.prototype.getProviders=function(){return this.options.providers},e.prototype.getProvider=function(e){return s(this.options.providers,function(t){return t.name===e})},e.prototype.get=function(e){var t=this.container.get(e);return void 0!==t?t:null},e.prototype.getApps$=function(e){return void 0===e&&(e=null),e?this._apps$.pipe(v.map(function(t){return t.filter(function(t){return t.regions.indexOf(e)>-1})})):this._apps$},e.prototype.registerApp=function(t,r){void 0===t&&(t=e),void 0===r&&(r={});var n=o({multi:!1},r);if(void 0!==n.name&&Object.defineProperty(t,"frintAppName",{value:n.name,configurable:!0}),-1!==p(this._appsCollection,function(e){return e.name===t.frintAppName}))throw new Error("App '"+t.frintAppName+"' has been already registered before.");this._appsCollection.push(o({},n,{name:t.frintAppName,appClass:t,instances:{},regions:n.regions||[]})),!1===n.multi&&this.instantiateApp(t.frintAppName),this._apps$.next(this._appsCollection)},e.prototype.hasAppInstance=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var n=this.getAppInstance(e,t,r);return!(!n||void 0===n)},e.prototype.getAppInstance=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var o=p(this._appsCollection,function(t){return t.name===e});if(-1===o)return null;var i=this._appsCollection[o],s=n(t,r,i.multi),a=i.instances[s];return a&&void 0!==a?a:null},e.prototype.getAppOnceAvailable$=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var o=this.getRootApp(),i=o.getAppInstance(e,t,r);return i?f.of(i):o._apps$.pipe(l.concatMap(function(e){return e}),d.find(function(t){return t.name===e}),v.map(function(e){var o=n(t,r,e.multi);return e.instances[o]}),h.first())},e.prototype.instantiateApp=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var i=p(this._appsCollection,function(t){return t.appClass.frintAppName===e});if(-1===i)throw new Error("No app found with name '"+e+"'.");var s=this._appsCollection[i],a=n(t,r,s.multi);return this._appsCollection[i].instances[a]=new s.appClass(o({},u(s,["AppClass","instances"]),{name:s.appClass.frintAppName,parentApp:this})),this._appsCollection[i].instances[a]},e.prototype.destroyApp=function(e,t,r){void 0===t&&(t=null),void 0===r&&(r=null);var o=p(this._appsCollection,function(t){return!(!t||!t.appClass)&&t.appClass.frintAppName===e});if(-1===o)throw new Error("No app found with name '"+e+"'.");var i=this._appsCollection[o],s=n(t,r,i.multi);if(void 0===this._appsCollection[o].instances[s])throw new Error("No instance with key '"+s+"' found for app with name '"+e+"'.");this._appsCollection[o].instances[s].beforeDestroy(),delete this._appsCollection[o].instances[s]},e.prototype.beforeDestroy=function(){return this.options.beforeDestroy.bind(this)()},e.prototype._registerRootProviders=function(){var e=this,t=this.getParentApps();0!==t.length&&t.reverse().forEach(function(t){t.getProviders().forEach(function(r){if(r.cascade){var n=Object.assign({},u(r,["useClass","useValue","useFactory"]));return r.scoped?"useValue"in r?void e.container.register(o({},n,{useValue:t.get(r.name)})):"useClass"in r?void e.container.register(o({},n,{useClass:r.useClass})):void("useFactory"in r&&e.container.register(o({},n,{useFactory:r.useFactory}))):void e.container.register(o({},n,{useValue:t.get(r.name)}))}})})},e}();t.App=m},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2);t.createApp=n.default;var o=r(0);t.App=o.App},function(e,t,r){"use strict";function n(e,t){var r=s({},e,t);return["initialize","beforeDestroy"].forEach(function(n){"function"==typeof e[n]&&"function"==typeof t[n]&&(r[n]=function(){e[n].call(this),t[n].call(this)})}),r}function o(e){var t=function(t){function r(r){return void 0===r&&(r={}),t.call(this,n(e,r))||this}return i(r,t),r}(p.App);return void 0!==e.name&&Object.defineProperty(t,"frintAppName",{value:e.name,configurable:!0}),t}var i=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(t,"__esModule",{value:!0});var s=r(3),p=r(0);t.default=o},function(t,r){t.exports=e},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(5),i=n(o),s=r(6),p=n(s);t.default={createContainer:i.default,resolveContainer:p.default},e.exports=t.default},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=p({containerName:"container"},t);return function(){function t(){var o=this;n(this,t),this.registry={},Object.defineProperty(this.registry,r.containerName,{get:function(){return o}}),e.forEach(function(e){o.register(e)})}return s(t,[{key:"getDeps",value:function(e){var t=this,r=e.name,n={};return Array.isArray(e.deps)?e.deps.forEach(function(e){if(!(e in t.registry))throw new Error("For provider '"+r+"', dependency '"+e+"' is not available yet.");n[e]=t.registry[e]}):"object"===i(e.deps)&&Object.keys(e.deps).forEach(function(o){if(!(o in t.registry))throw new Error("For provider '"+r+"', dependency '"+o+"' is not available yet.");var i=e.deps[o];n[i]=t.registry[o]}),n}},{key:"register",value:function(e){if("string"!=typeof e.name)throw new Error("Provider has no 'name' key.");var t=e.name;if("useValue"in e)this.registry[t]=e.useValue;else if("useFactory"in e)this.registry[t]=e.useFactory(this.getDeps(e));else if("useClass"in e)this.registry[t]=new e.useClass(this.getDeps(e));else{if(!("useDefinedValue"in e))throw new Error("No value given for '"+t+"' provider.");Object.defineProperty(this.registry,t,{get:function(){return e.useDefinedValue}})}}},{key:"get",value:function(e){return this.registry[e]}}]),t}()}Object.defineProperty(t,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.default=o,e.exports=t.default},function(e,t,r){"use strict";function n(e){return new e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n,e.exports=t.default},function(e,r){e.exports=t},function(e,t){e.exports=r},function(e,t){e.exports=n},function(e,t){e.exports=o},function(e,t){e.exports=i},function(e,t){e.exports=s},function(e,t){e.exports=p},function(e,t){e.exports=a},function(e,t){e.exports=u},function(e,t){e.exports=c}])}); |
import { Container, Provider } from 'frint-di'; | ||
import { Observable } from 'rxjs/Observable'; | ||
export interface Methods { | ||
[key: string]: () => any; | ||
} | ||
export interface ProviderNames { | ||
@@ -34,2 +37,3 @@ component: string; | ||
name?: string; | ||
methods?: Methods; | ||
parentApp?: App; | ||
@@ -46,2 +50,3 @@ providers?: FrintProvider[]; | ||
export declare class App { | ||
[method: string]: any; | ||
container: Container; | ||
@@ -48,0 +53,0 @@ private options; |
import { Container, Provider } from 'frint-di'; | ||
import { Observable } from 'rxjs/Observable'; | ||
export interface Methods { | ||
[key: string]: () => any; | ||
} | ||
export interface ProviderNames { | ||
@@ -34,2 +37,3 @@ component: string; | ||
name?: string; | ||
methods?: Methods; | ||
parentApp?: App; | ||
@@ -46,2 +50,3 @@ providers?: FrintProvider[]; | ||
export declare class App { | ||
[method: string]: any; | ||
container: Container; | ||
@@ -48,0 +53,0 @@ private options; |
@@ -51,3 +51,3 @@ "use strict"; | ||
var _this = this; | ||
this.options = __assign({ name: null, parentApp: null, providers: [], providerNames: defaultProviderNames, | ||
this.options = __assign({ name: null, methods: {}, parentApp: null, providers: [], providerNames: defaultProviderNames, | ||
// lifecycle callbacks | ||
@@ -62,2 +62,12 @@ // tslint:disable-next-line:no-empty | ||
} | ||
// expose methods as class properties | ||
Object.keys(this.options.methods).forEach(function (methodName) { | ||
var method = _this.options.methods[methodName]; | ||
if (typeof method === 'function') { | ||
if (_this[methodName] !== undefined) { | ||
throw new Error("Cannot overwrite app's `" + methodName + "` property or method with options method."); | ||
} | ||
_this[methodName] = method.bind(_this); | ||
} | ||
}); | ||
// children - create Observable if root | ||
@@ -64,0 +74,0 @@ this._appsCollection = []; |
@@ -15,3 +15,3 @@ "use strict"; | ||
}); | ||
it('gets option value', function () { | ||
it('gets name option value', function () { | ||
var app = new App_1.App({ | ||
@@ -22,2 +22,22 @@ name: 'MyApp', | ||
}); | ||
it('exposes methods as class properties', function () { | ||
var methods = { | ||
foo: function () { return 'foo'; }, | ||
}; | ||
var app = new App_1.App({ | ||
name: 'MyApp', | ||
methods: methods, | ||
}); | ||
chai_1.expect(app.foo()).to.equal('foo'); | ||
}); | ||
it('does not overwrite app properties or methods with options methods', function () { | ||
var methods = { | ||
// tslint:disable-next-line:no-empty | ||
getName: function () { }, | ||
}; | ||
chai_1.expect(function () { return (new App_1.App({ | ||
name: 'MyApp', | ||
methods: methods, | ||
})); }).to.throw(/Cannot overwrite app's `getName` property or method with options method/); | ||
}); | ||
it('gets parent and root app', function () { | ||
@@ -24,0 +44,0 @@ var rootApp = new App_1.App({ |
{ | ||
"name": "frint", | ||
"version": "5.5.0", | ||
"version": "5.6.0", | ||
"description": "Core plugin for Frint", | ||
@@ -28,3 +28,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"frint-di": "^5.5.0", | ||
"frint-di": "^5.6.0", | ||
"lodash": "^4.13.1", | ||
@@ -35,3 +35,3 @@ "rxjs": "^5.5.0" | ||
"cross-env": "^5.0.5", | ||
"frint-config": "^5.5.0" | ||
"frint-config": "^5.6.0" | ||
}, | ||
@@ -38,0 +38,0 @@ "bugs": { |
@@ -278,2 +278,3 @@ # frint | ||
* `options.name`: (`String` [required]): Name of your App. | ||
* `options.methods`: (`Object` [optional]): Object with the methods your App exposes on the instance level. | ||
* `options.initialize`: (`Function` [optional]): Called when App is constructed. | ||
@@ -280,0 +281,0 @@ * `options.beforeDestroy`: (`Function` [optional]): Called when App is about to be destroyed. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
117576
1702
489
0
Updatedfrint-di@^5.6.0