Comparing version 0.3.0-alpha to 0.3.1-alpha
@@ -1,2 +0,2 @@ | ||
function t(t,e,n){Object.defineProperty(t,e,{get:()=>n(),enumerable:!0})}class e extends Error{}class n extends e{}class s extends e{}class i extends class extends class{}{on(t,e){return this.ee.on(t,e)}constructor(){super(),this._cache={},this._context={},this.ee=void 0,this.ee={events:{},emit(t,...e){(this.events[t]||[]).forEach(t=>t(...e))},on(t,e){return(this.events[t]=this.events[t]||[]).push(e),()=>this.events[t]=(this.events[t]||[]).filter(t=>t!==e)}}}get(t){if(null!=this._context[t]){const e=this._cache[t];if(null!=e)return e;const n=(t,e)=>{this._cache[t]=e,this.ee.emit("containerUpserted",{key:t,newContainer:e})},s=this._context[t];if("function"==typeof s){const e=s();return n(t,e),e}return n(t,s),s}throw new n(`Can't find token '${t}' value`)}_updateContext(t){for(const[e,n]of Object.entries(t))null!=this._context[e]&&this.ee.emit("containerUpdated",{key:e,newContainer:n}),this._context[e]=n,this._cache[e]=null,this.ee.emit("containerUpserted",{key:e,newContainer:n})}subscribeToContiner(t,e){var n=this;return this.ee.on("containerUpserted",async function(s){t===s.key&&e(await n.get(t))})}getTokens(){return Object.fromEntries(Object.keys(this._context).map(t=>[t,t]))}}{constructor(){super()}upsert(t){let e="function"==typeof t?t(this):t;return this._updateContext(e),this}add(t){let e="function"==typeof t?t(this):t,n=Object.keys(this.getTokens()).filter(t=>null!=e[t]);if(0!==n.length)throw new s(`Tokens already exist: ['${n.join("', '")}']`);return this.upsert(e)}_extractTokens(t){return"function"==typeof t?t(this.getTokens()):t}subscribeToContinerSet(t,e){var n=this;let s=this._extractTokens(t);return this.ee.on("containerUpserted",async function(t){s.includes(t.key)&&e(await n.getContainerSet(s))})}async getContainerSet(t){let e=this._extractTokens(t),n=[],s=[];for(let t of e)this.containers[t]instanceof Promise&&(n.push(t),s.push(this.containers[t]));let i={};e.forEach(t=>{i[t]=this.containers[t]});const r=await Promise.all(s);return n.forEach((t,e)=>{i[t]=r[e]}),i}get containers(){let e={};for(let n in this.getTokens())t(e,n,()=>this.get(n));return e}}function r(){return new i}export{i as NodeApi,r as makeRoot}; | ||
function t(t,e,n){Object.defineProperty(t,e,{get:()=>n(),enumerable:!0})}class e extends Error{}class n extends e{}class s extends e{}class i extends class extends class{}{on(t,e){return this.ee.on(t,e)}constructor(){super(),this._cache={},this._context={},this.ee=void 0,this.ee={events:{},emit(t,...e){(this.events[t]||[]).forEach(t=>t(...e))},on(t,e){return(this.events[t]=this.events[t]||[]).push(e),()=>this.events[t]=(this.events[t]||[]).filter(t=>t!==e)}}}get(t){if(null!=this._context[t]){const e=this._cache[t];if(null!=e)return e;const n=(t,e)=>{this._cache[t]=e,this.ee.emit("containerUpserted",{key:t,newContainer:e})},s=this._context[t];if("function"==typeof s){const e=s();return n(t,e),e}return n(t,s),s}throw new n(`Can't find token '${t}' value`)}_updateContext(t){for(const[e,n]of Object.entries(t))null!=this._context[e]&&this.ee.emit("containerUpdated",{key:e,newContainer:n}),this._context[e]=n,this._cache[e]=null,this.ee.emit("containerUpserted",{key:e,newContainer:n})}subscribeToContiner(t,e){var n=this;return this.ee.on("containerUpserted",async function(s){t===s.key&&e(await n.get(t))})}getTokens(){return Object.fromEntries(Object.keys(this._context).map(t=>[t,t]))}}{constructor(){super()}upsert(t){let e="function"==typeof t?t(this.containers,this):t;return this._updateContext(e),this}add(t){let e="function"==typeof t?t(this.containers,this):t,n=Object.keys(this.getTokens()).filter(t=>null!=e[t]);if(0!==n.length)throw new s(`Tokens already exist: ['${n.join("', '")}']`);return this.upsert(e)}_extractTokens(t){return"function"==typeof t?t(this.getTokens()):t}subscribeToContinerSet(t,e){var n=this;let s=this._extractTokens(t);return this.ee.on("containerUpserted",async function(t){s.includes(t.key)&&e(await n.getContainerSet(s))})}async getContainerSet(t){let e=this._extractTokens(t),n=[],s=[];for(let t of e)this.containers[t]instanceof Promise&&(n.push(t),s.push(this.containers[t]));let i={};e.forEach(t=>{i[t]=this.containers[t]});const r=await Promise.all(s);return n.forEach((t,e)=>{i[t]=r[e]}),i}get containers(){let e={};for(let n in this.getTokens())t(e,n,()=>this.get(n));return e}}function r(){return new i}export{i as NodeApi,r as makeRoot}; | ||
//# sourceMappingURL=iti.modern.js.map |
@@ -1,2 +0,2 @@ | ||
function t(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,n(t,e)}function e(t){return e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},e(t)}function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function o(t,e,i){return o=r()?Reflect.construct:function(t,e,r){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return r&&n(i,r.prototype),i},o.apply(null,arguments)}function i(t){var r="function"==typeof Map?new Map:void 0;return i=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,i)}function i(){return o(t,arguments,e(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,t)},i(t)}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var c=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n}(/*#__PURE__*/i(Error)),a=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n}(c),f=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n}(c),s=/*#__PURE__*/function(e){function n(){return e.call(this)||this}t(n,e);var r,o,i=n.prototype;return i.upsert=function(t){var e="function"==typeof t?t(this):t;return this._updateContext(e),this},i.add=function(t){var e="function"==typeof t?t(this):t,n=Object.keys(this.getTokens()).filter(function(t){return null!=e[t]});if(0!==n.length)throw new f("Tokens already exist: ['"+n.join("', '")+"']");return this.upsert(e)},i._extractTokens=function(t){return"function"==typeof t?t(this.getTokens()):t},i.subscribeToContinerSet=function(t,e){var n=this,r=this._extractTokens(t);return this.ee.on("containerUpserted",function(t){try{var o=function(){if(r.includes(t.key))return Promise.resolve(n.getContainerSet(r)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},i.getContainerSet=function(t){try{for(var e,n=this,r=n._extractTokens(t),o=[],i=[],c=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}(t))){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(e=c()).done;){var a=e.value;n.containers[a]instanceof Promise&&(o.push(a),i.push(n.containers[a]))}var f={};return r.forEach(function(t){f[t]=n.containers[t]}),Promise.resolve(Promise.all(i)).then(function(t){return o.forEach(function(e,n){f[e]=t[n]}),f})}catch(t){return Promise.reject(t)}},r=n,(o=[{key:"containers",get:function(){var t=this,e={},n=function(n){!function(t,e,n){Object.defineProperty(t,e,{get:function(){return n()},enumerable:!0})}(e,n,function(){return t.get(n)})};for(var r in this.getTokens())n(r);return e}}])&&function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(r.prototype,o),Object.defineProperty(r,"prototype",{writable:!1}),n}(/*#__PURE__*/function(e){t(r,e);var n=r.prototype;function r(){var t;return(t=e.call(this)||this)._cache={},t._context={},t.ee=void 0,t.ee={events:{},emit:function(t){var e=arguments;(this.events[t]||[]).forEach(function(t){return t.apply(void 0,[].slice.call(e,1))})},on:function(t,e){var n=this;return(this.events[t]=this.events[t]||[]).push(e),function(){return n.events[t]=(n.events[t]||[]).filter(function(t){return t!==e})}}},t}return n.on=function(t,e){return this.ee.on(t,e)},n.get=function(t){var e=this;if(null!=this._context[t]){var n=this._cache[t];if(null!=n)return n;var r=function(t,n){e._cache[t]=n,e.ee.emit("containerUpserted",{key:t,newContainer:n})},o=this._context[t];if("function"==typeof o){var i=o();return r(t,i),i}return r(t,o),o}throw new a("Can't find token '"+t+"' value")},n._updateContext=function(t){for(var e=0,n=Object.entries(t);e<n.length;e++){var r=n[e],o=r[0],i=r[1];null!=this._context[o]&&this.ee.emit("containerUpdated",{key:o,newContainer:i}),this._context[o]=i,this._cache[o]=null,this.ee.emit("containerUpserted",{key:o,newContainer:i})}},n.subscribeToContiner=function(t,e){var n=this;return this.ee.on("containerUpserted",function(r){try{var o=function(){if(t===r.key)return Promise.resolve(n.get(t)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},n.getTokens=function(){return Object.fromEntries(Object.keys(this._context).map(function(t){return[t,t]}))},r}(function(){}));function l(){return new s}export{s as NodeApi,l as makeRoot}; | ||
function t(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,n(t,e)}function e(t){return e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},e(t)}function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function o(t,e,i){return o=r()?Reflect.construct:function(t,e,r){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return r&&n(i,r.prototype),i},o.apply(null,arguments)}function i(t){var r="function"==typeof Map?new Map:void 0;return i=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,i)}function i(){return o(t,arguments,e(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,t)},i(t)}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var c=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n}(/*#__PURE__*/i(Error)),a=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n}(c),f=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n}(c),s=/*#__PURE__*/function(e){function n(){return e.call(this)||this}t(n,e);var r,o,i=n.prototype;return i.upsert=function(t){var e="function"==typeof t?t(this.containers,this):t;return this._updateContext(e),this},i.add=function(t){var e="function"==typeof t?t(this.containers,this):t,n=Object.keys(this.getTokens()).filter(function(t){return null!=e[t]});if(0!==n.length)throw new f("Tokens already exist: ['"+n.join("', '")+"']");return this.upsert(e)},i._extractTokens=function(t){return"function"==typeof t?t(this.getTokens()):t},i.subscribeToContinerSet=function(t,e){var n=this,r=this._extractTokens(t);return this.ee.on("containerUpserted",function(t){try{var o=function(){if(r.includes(t.key))return Promise.resolve(n.getContainerSet(r)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},i.getContainerSet=function(t){try{for(var e,n=this,r=n._extractTokens(t),o=[],i=[],c=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}(t))){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(e=c()).done;){var a=e.value;n.containers[a]instanceof Promise&&(o.push(a),i.push(n.containers[a]))}var f={};return r.forEach(function(t){f[t]=n.containers[t]}),Promise.resolve(Promise.all(i)).then(function(t){return o.forEach(function(e,n){f[e]=t[n]}),f})}catch(t){return Promise.reject(t)}},r=n,(o=[{key:"containers",get:function(){var t=this,e={},n=function(n){!function(t,e,n){Object.defineProperty(t,e,{get:function(){return n()},enumerable:!0})}(e,n,function(){return t.get(n)})};for(var r in this.getTokens())n(r);return e}}])&&function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(r.prototype,o),Object.defineProperty(r,"prototype",{writable:!1}),n}(/*#__PURE__*/function(e){t(r,e);var n=r.prototype;function r(){var t;return(t=e.call(this)||this)._cache={},t._context={},t.ee=void 0,t.ee={events:{},emit:function(t){var e=arguments;(this.events[t]||[]).forEach(function(t){return t.apply(void 0,[].slice.call(e,1))})},on:function(t,e){var n=this;return(this.events[t]=this.events[t]||[]).push(e),function(){return n.events[t]=(n.events[t]||[]).filter(function(t){return t!==e})}}},t}return n.on=function(t,e){return this.ee.on(t,e)},n.get=function(t){var e=this;if(null!=this._context[t]){var n=this._cache[t];if(null!=n)return n;var r=function(t,n){e._cache[t]=n,e.ee.emit("containerUpserted",{key:t,newContainer:n})},o=this._context[t];if("function"==typeof o){var i=o();return r(t,i),i}return r(t,o),o}throw new a("Can't find token '"+t+"' value")},n._updateContext=function(t){for(var e=0,n=Object.entries(t);e<n.length;e++){var r=n[e],o=r[0],i=r[1];null!=this._context[o]&&this.ee.emit("containerUpdated",{key:o,newContainer:i}),this._context[o]=i,this._cache[o]=null,this.ee.emit("containerUpserted",{key:o,newContainer:i})}},n.subscribeToContiner=function(t,e){var n=this;return this.ee.on("containerUpserted",function(r){try{var o=function(){if(t===r.key)return Promise.resolve(n.get(t)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},n.getTokens=function(){return Object.fromEntries(Object.keys(this._context).map(function(t){return[t,t]}))},r}(function(){}));function l(){return new s}export{s as NodeApi,l as makeRoot}; | ||
//# sourceMappingURL=iti.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).iti={})}(this,function(t){function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function i(t,e,n){return i=o()?Reflect.construct:function(t,e,n){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return n&&r(i,n.prototype),i},i.apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return i(t,arguments,n(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),r(o,t)},u(t)}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var f=/*#__PURE__*/function(t){function n(){return t.apply(this,arguments)||this}return e(n,t),n}(/*#__PURE__*/u(Error)),a=/*#__PURE__*/function(t){function n(){return t.apply(this,arguments)||this}return e(n,t),n}(f),s=/*#__PURE__*/function(t){function n(){return t.apply(this,arguments)||this}return e(n,t),n}(f),l=/*#__PURE__*/function(t){e(r,t);var n=r.prototype;function r(){var e;return(e=t.call(this)||this)._cache={},e._context={},e.ee=void 0,e.ee={events:{},emit:function(t){var e=arguments;(this.events[t]||[]).forEach(function(t){return t.apply(void 0,[].slice.call(e,1))})},on:function(t,e){var n=this;return(this.events[t]=this.events[t]||[]).push(e),function(){return n.events[t]=(n.events[t]||[]).filter(function(t){return t!==e})}}},e}return n.on=function(t,e){return this.ee.on(t,e)},n.get=function(t){var e=this;if(null!=this._context[t]){var n=this._cache[t];if(null!=n)return n;var r=function(t,n){e._cache[t]=n,e.ee.emit("containerUpserted",{key:t,newContainer:n})},o=this._context[t];if("function"==typeof o){var i=o();return r(t,i),i}return r(t,o),o}throw new a("Can't find token '"+t+"' value")},n._updateContext=function(t){for(var e=0,n=Object.entries(t);e<n.length;e++){var r=n[e],o=r[0],i=r[1];null!=this._context[o]&&this.ee.emit("containerUpdated",{key:o,newContainer:i}),this._context[o]=i,this._cache[o]=null,this.ee.emit("containerUpserted",{key:o,newContainer:i})}},n.subscribeToContiner=function(t,e){var n=this;return this.ee.on("containerUpserted",function(r){try{var o=function(){if(t===r.key)return Promise.resolve(n.get(t)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},n.getTokens=function(){return Object.fromEntries(Object.keys(this._context).map(function(t){return[t,t]}))},r}(function(){}),p=/*#__PURE__*/function(t){function n(){return t.call(this)||this}e(n,t);var r,o,i=n.prototype;return i.upsert=function(t){var e="function"==typeof t?t(this):t;return this._updateContext(e),this},i.add=function(t){var e="function"==typeof t?t(this):t,n=Object.keys(this.getTokens()).filter(function(t){return null!=e[t]});if(0!==n.length)throw new s("Tokens already exist: ['"+n.join("', '")+"']");return this.upsert(e)},i._extractTokens=function(t){return"function"==typeof t?t(this.getTokens()):t},i.subscribeToContinerSet=function(t,e){var n=this,r=this._extractTokens(t);return this.ee.on("containerUpserted",function(t){try{var o=function(){if(r.includes(t.key))return Promise.resolve(n.getContainerSet(r)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},i.getContainerSet=function(t){try{for(var e,n=this,r=n._extractTokens(t),o=[],i=[],u=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return c(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(t,e):void 0}}(t))){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(e=u()).done;){var f=e.value;n.containers[f]instanceof Promise&&(o.push(f),i.push(n.containers[f]))}var a={};return r.forEach(function(t){a[t]=n.containers[t]}),Promise.resolve(Promise.all(i)).then(function(t){return o.forEach(function(e,n){a[e]=t[n]}),a})}catch(t){return Promise.reject(t)}},r=n,(o=[{key:"containers",get:function(){var t=this,e={},n=function(n){!function(t,e,n){Object.defineProperty(t,e,{get:function(){return n()},enumerable:!0})}(e,n,function(){return t.get(n)})};for(var r in this.getTokens())n(r);return e}}])&&function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(r.prototype,o),Object.defineProperty(r,"prototype",{writable:!1}),n}(l);t.NodeApi=p,t.makeRoot=function(){return new p}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).iti={})}(this,function(t){function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function i(t,e,n){return i=o()?Reflect.construct:function(t,e,n){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return n&&r(i,n.prototype),i},i.apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return i(t,arguments,n(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),r(o,t)},u(t)}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var f=/*#__PURE__*/function(t){function n(){return t.apply(this,arguments)||this}return e(n,t),n}(/*#__PURE__*/u(Error)),a=/*#__PURE__*/function(t){function n(){return t.apply(this,arguments)||this}return e(n,t),n}(f),s=/*#__PURE__*/function(t){function n(){return t.apply(this,arguments)||this}return e(n,t),n}(f),l=/*#__PURE__*/function(t){e(r,t);var n=r.prototype;function r(){var e;return(e=t.call(this)||this)._cache={},e._context={},e.ee=void 0,e.ee={events:{},emit:function(t){var e=arguments;(this.events[t]||[]).forEach(function(t){return t.apply(void 0,[].slice.call(e,1))})},on:function(t,e){var n=this;return(this.events[t]=this.events[t]||[]).push(e),function(){return n.events[t]=(n.events[t]||[]).filter(function(t){return t!==e})}}},e}return n.on=function(t,e){return this.ee.on(t,e)},n.get=function(t){var e=this;if(null!=this._context[t]){var n=this._cache[t];if(null!=n)return n;var r=function(t,n){e._cache[t]=n,e.ee.emit("containerUpserted",{key:t,newContainer:n})},o=this._context[t];if("function"==typeof o){var i=o();return r(t,i),i}return r(t,o),o}throw new a("Can't find token '"+t+"' value")},n._updateContext=function(t){for(var e=0,n=Object.entries(t);e<n.length;e++){var r=n[e],o=r[0],i=r[1];null!=this._context[o]&&this.ee.emit("containerUpdated",{key:o,newContainer:i}),this._context[o]=i,this._cache[o]=null,this.ee.emit("containerUpserted",{key:o,newContainer:i})}},n.subscribeToContiner=function(t,e){var n=this;return this.ee.on("containerUpserted",function(r){try{var o=function(){if(t===r.key)return Promise.resolve(n.get(t)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},n.getTokens=function(){return Object.fromEntries(Object.keys(this._context).map(function(t){return[t,t]}))},r}(function(){}),p=/*#__PURE__*/function(t){function n(){return t.call(this)||this}e(n,t);var r,o,i=n.prototype;return i.upsert=function(t){var e="function"==typeof t?t(this.containers,this):t;return this._updateContext(e),this},i.add=function(t){var e="function"==typeof t?t(this.containers,this):t,n=Object.keys(this.getTokens()).filter(function(t){return null!=e[t]});if(0!==n.length)throw new s("Tokens already exist: ['"+n.join("', '")+"']");return this.upsert(e)},i._extractTokens=function(t){return"function"==typeof t?t(this.getTokens()):t},i.subscribeToContinerSet=function(t,e){var n=this,r=this._extractTokens(t);return this.ee.on("containerUpserted",function(t){try{var o=function(){if(r.includes(t.key))return Promise.resolve(n.getContainerSet(r)).then(function(t){e(t)})}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(t){return Promise.reject(t)}})},i.getContainerSet=function(t){try{for(var e,n=this,r=n._extractTokens(t),o=[],i=[],u=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return c(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(t,e):void 0}}(t))){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(e=u()).done;){var f=e.value;n.containers[f]instanceof Promise&&(o.push(f),i.push(n.containers[f]))}var a={};return r.forEach(function(t){a[t]=n.containers[t]}),Promise.resolve(Promise.all(i)).then(function(t){return o.forEach(function(e,n){a[e]=t[n]}),a})}catch(t){return Promise.reject(t)}},r=n,(o=[{key:"containers",get:function(){var t=this,e={},n=function(n){!function(t,e,n){Object.defineProperty(t,e,{get:function(){return n()},enumerable:!0})}(e,n,function(){return t.get(n)})};for(var r in this.getTokens())n(r);return e}}])&&function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(r.prototype,o),Object.defineProperty(r,"prototype",{writable:!1}),n}(l);t.NodeApi=p,t.makeRoot=function(){return new p}}); | ||
//# sourceMappingURL=iti.umd.js.map |
@@ -1,6 +0,6 @@ | ||
export declare class SnowSplashError extends Error { | ||
export declare class ItiError extends Error { | ||
} | ||
export declare class SnowSplashResolveError extends SnowSplashError { | ||
export declare class ItiResolveError extends ItiError { | ||
} | ||
export declare class SnowSplashTokenError extends SnowSplashError { | ||
export declare class ItiTokenError extends ItiError { | ||
} |
@@ -50,6 +50,9 @@ import { Intersection } from "utility-types"; | ||
}; | ||
declare type ContextGetter<Context extends {}> = { | ||
[CK in keyof Context]: UnpackFunction<Context[CK]>; | ||
}; | ||
export declare class NodeApi<Context extends {}> extends Node<Context> { | ||
constructor(); | ||
upsert<NewContext extends {}>(newContext: NewContext | ((self: NodeApi<Context>) => NewContext)): NodeApi<Assign4<Context, NewContext>>; | ||
add<NewContext extends Intersection<MyRecord<Context, "You are overwriting this token. It is not safe. Use an unsafe `upsert` method">, NewContext>>(newContextOrCb: NewContext | ((self: NodeApi<Context>) => NewContext)): NodeApi<Assign4<Context, NewContext>>; | ||
upsert<NewContext extends {}>(newContext: NewContext | ((containers: ContextGetter<Context>, self: NodeApi<Context>) => NewContext)): NodeApi<Assign4<Context, NewContext>>; | ||
add<NewContext extends Intersection<MyRecord<Context, "You are overwriting this token. It is not safe. Use an unsafe `upsert` method">, NewContext>>(newContextOrCb: NewContext | ((containers: ContextGetter<Context>, self: NodeApi<Context>) => NewContext)): NodeApi<Assign4<Context, NewContext>>; | ||
_extractTokens<T extends keyof Context>(tokensOrCb: KeysOrCb<Context>): T[]; | ||
@@ -60,5 +63,5 @@ subscribeToContinerSet<T extends keyof Context>(tokensOrCb: KeysOrCb<Context>, cb: (container: { | ||
getContainerSet<T extends keyof Context>(tokensOrCb: KeysOrCb<Context>): Promise<{ [K in T]: UnpromisifyObject<UnpackObject<Context>>[K]; }>; | ||
get containers(): { [CK in keyof Context]: UnpackFunction<Context[CK]>; }; | ||
get containers(): ContextGetter<Context>; | ||
} | ||
export declare function makeRoot(): NodeApi<{}>; | ||
export {}; |
{ | ||
"name": "iti", | ||
"version": "0.3.0-alpha", | ||
"version": "0.3.1-alpha", | ||
"description": "~1kB inversion of control container for Typescript/Javascrith with a focus on async flow", | ||
@@ -22,4 +22,3 @@ "type": "module", | ||
"jestWatch": "jest --watch --verbose", | ||
"tsd": "tsd tsd_project", | ||
"prepare-not": "install-peers" | ||
"tsd": "tsd tsd_project" | ||
}, | ||
@@ -34,3 +33,2 @@ "dependencies": { | ||
"@types/react": "^17.0.38", | ||
"install-peers-cli": "^2.2.0", | ||
"jest": "^27.4.7", | ||
@@ -43,6 +41,2 @@ "microbundle": "^0.14.2", | ||
}, | ||
"peerDependencies": { | ||
"react": ">=16", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"engines": { | ||
@@ -49,0 +43,0 @@ "node": ">=12" |
@@ -1,10 +0,10 @@ | ||
<a href="https://www.npmjs.org/package/snow-splash"><img src="https://img.shields.io/npm/v/snow-splash.svg" alt="npm"></a> | ||
![CI](https://github.com/molszanski/snow-splash/actions/workflows/lib-test.yml/badge.svg) | ||
<a href="https://unpkg.com/snow-splash/dist/snow-splash.modern.js"><img src="https://img.badgesize.io/https://unpkg.com/snow-splash/dist/snow-splash.modern.js?compression=gzip" alt="gzip size"></a> | ||
<a href="https://www.npmjs.org/package/iti"><img src="https://img.shields.io/npm/v/iti.svg" alt="npm"></a> | ||
![CI](https://github.com/molszanski/iti/actions/workflows/lib-test.yml/badge.svg) | ||
<a href="https://unpkg.com/iti/dist/iti.modern.js"><img src="https://img.badgesize.io/https://unpkg.com/iti/dist/iti.modern.js?compression=gzip" alt="gzip size"></a> | ||
π§ **library is in alpha dev mode** π§ | ||
π§ **library is in beta mode** π§ | ||
# Snow Splash | ||
# Iti | ||
> ~2kB inversion of control container for Typescript/Javascript for constructor injection with a focus on async flow | ||
> ~1kB inversion of control container for Typescript/Javascript for constructor injection with a focus on async flow | ||
@@ -22,3 +22,3 @@ - **fully async:** merges async code and a constructor injection via async functions (asynchronous factory pattern) | ||
Snow-Splash is an alternative to [InversifyJS](https://github.com/inversify/InversifyJS) and [microsoft/tsyringe](https://github.com/microsoft/tsyringe). It relies on plain JS functions, objects and familiar patterns. There is no need to learn complex API to use it in a full capacity. | ||
`iti` is an alternative to [InversifyJS](https://github.com/inversify/InversifyJS) and [microsoft/tsyringe](https://github.com/microsoft/tsyringe). It relies on plain JS functions, objects and familiar patterns. There is no need to learn complex API to use it in a full capacity. | ||
@@ -28,3 +28,3 @@ ## Usage | ||
``` | ||
npm install -S snow-splash | ||
npm install -S iti | ||
``` | ||
@@ -47,3 +47,3 @@ | ||
// Step 2: Add and read simple tokens | ||
import { makeRoot } from "snow-splash" | ||
import { makeRoot } from "iti" | ||
let root = makeRoot().add({ | ||
@@ -63,3 +63,3 @@ userManual: "Please preheat before use", | ||
// Step 4: Add an async provider | ||
const node = root.add((node) => ({ | ||
const node = root.add((containers, node) => ({ | ||
kitchen: async () => | ||
@@ -71,3 +71,3 @@ kitchenContainer(await node.getContainerSet(["userManual", "oven"])), | ||
// Typical usage in React | ||
// Typical React usage | ||
export const PizzaData = () => { | ||
@@ -120,7 +120,7 @@ const [oven] = useContainer().oven | ||
}) | ||
.upsert((node) => ({ | ||
.upsert((containers, node) => ({ | ||
userManual: "Works better when hot", | ||
preheatedOven: async () => { | ||
await node.get("oven").preheat() | ||
return node.get("oven") | ||
await containers.oven.preheat() | ||
return containers.oven | ||
}, | ||
@@ -222,3 +222,3 @@ })) | ||
The best way to get started is to check [a CRA Pizza example](https://github.com/molszanski/snow-splash/tree/master/examples/cra/src/containers) | ||
The best way to get started is to check [a CRA Pizza example](https://github.com/molszanski/iti/tree/master/examples/cra/src/containers) | ||
@@ -239,5 +239,5 @@ Initial wiring | ||
.add({ aCont: async () => provideAContainer() }) | ||
.add((c) => { | ||
.add((containers) => { | ||
return { | ||
bCont: async () => provideBContainer(await c.get("aCont")), | ||
bCont: async () => provideBContainer(await containers.aCont), | ||
} | ||
@@ -247,4 +247,3 @@ }) | ||
return { | ||
cCont: async () => | ||
provideCContainer(await c.get("aCont"), await c.get("bCont"), k), | ||
cCont: async () => provideCContainer(await c.aCont, await c.bCont, k), | ||
} | ||
@@ -258,3 +257,3 @@ }) | ||
Snow-Splash has a good typescript support | ||
Iti has a great typescript support. All types are resolved automatically and check at compile time. | ||
@@ -376,3 +375,3 @@ ![Autocomplete](./docs/1.png) | ||
With Snow-Splash your application logic is not mixed with the framework code | ||
With Iti your application logic is not mixed with the framework code | ||
@@ -379,0 +378,0 @@ ```ts |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
102184
1
10
316
0
410