Ver código fonte

fix(observable callback)

Ryan Chandler 4 anos atrás
pai
commit
9c039f6028

+ 1 - 1
dist/spruce.js

@@ -1,2 +1,2 @@
-var t=function(t){return null==t},e=function(t){return Object.getPrototypeOf(t)===Object.prototype},r=function(n,s){return Object.entries(n).forEach(function(i){var o=i[0],u=i[1];t(u)||!e(u)&&!Array.isArray(u)||(n[o]=r(u,s))}),new Proxy(n,{set:function(n,i,o){return!t(o)&&e(o)&&(o=r(o,s)),s.set(n,i,n[i]=o),!0}})},n={stores:{},subscribers:[],start:function(){try{var t=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){t.emit("init"),t.attach(),document.addEventListener("turbolinks:render",t.attach),t.stores=r(t.stores,{set:function(e,r,n){t.events.runWatchers(t.stores,e,r,n),t.updateSubscribers()}})})}catch(t){return Promise.reject(t)}},attach:function(){if(!window.Alpine)throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var t=this;window.Alpine.addMagicProperty("store",function(e){return t.subscribe(e),t.stores})},store:function(t,e){return this.stores[t]||(this.stores[t]=e),this.stores[t]},reset:function(t,e){this.stores[t]=e},subscribe:function(t){return this.subscribers.includes(t)||this.subscribers.push(t),this.stores},updateSubscribers:function(){this.subscribers.filter(function(t){return!!t.__x}).forEach(function(t){t.__x.updateElements(t)})}},s=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=n,window.Spruce.start(),s(t)},module.exports=n;
+var t=function(t){return null==t},e=function(t){return Object.getPrototypeOf(t)===Object.prototype},r=function(n,s){return Object.entries(n).forEach(function(i){var o=i[0],u=i[1];t(u)||!e(u)&&!Array.isArray(u)||(n[o]=r(u,s))}),new Proxy(n,{set:function(n,i,o){return!t(o)&&e(o)&&(o=r(o,s)),s.set(n,i,n[i]=o),!0}})},n={stores:{},subscribers:[],start:function(){try{var t=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){t.attach(),document.addEventListener("turbolinks:render",t.attach),t.stores=r(t.stores,{set:t.updateSubscribers.bind(t)})})}catch(t){return Promise.reject(t)}},attach:function(){if(!window.Alpine)throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var t=this;window.Alpine.addMagicProperty("store",function(e){return t.subscribe(e),t.stores})},store:function(t,e){return this.stores[t]||(this.stores[t]=e),this.stores[t]},reset:function(t,e){this.stores[t]=e},subscribe:function(t){return this.subscribers.includes(t)||this.subscribers.push(t),this.stores},updateSubscribers:function(){this.subscribers.filter(function(t){return!!t.__x}).forEach(function(t){t.__x.updateElements(t)})}},s=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=n,window.Spruce.start(),s(t)},module.exports=n;
 //# sourceMappingURL=spruce.js.map

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/spruce.js.map


+ 1 - 1
dist/spruce.module.js

@@ -1,2 +1,2 @@
-var t=function(t){return null==t},e=function(t){return Object.getPrototypeOf(t)===Object.prototype},r=function(n,s){return Object.entries(n).forEach(function(i){var o=i[0],u=i[1];t(u)||!e(u)&&!Array.isArray(u)||(n[o]=r(u,s))}),new Proxy(n,{set:function(n,i,o){return!t(o)&&e(o)&&(o=r(o,s)),s.set(n,i,n[i]=o),!0}})},n={stores:{},subscribers:[],start:function(){try{var t=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){t.emit("init"),t.attach(),document.addEventListener("turbolinks:render",t.attach),t.stores=r(t.stores,{set:function(e,r,n){t.events.runWatchers(t.stores,e,r,n),t.updateSubscribers()}})})}catch(t){return Promise.reject(t)}},attach:function(){if(!window.Alpine)throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var t=this;window.Alpine.addMagicProperty("store",function(e){return t.subscribe(e),t.stores})},store:function(t,e){return this.stores[t]||(this.stores[t]=e),this.stores[t]},reset:function(t,e){this.stores[t]=e},subscribe:function(t){return this.subscribers.includes(t)||this.subscribers.push(t),this.stores},updateSubscribers:function(){this.subscribers.filter(function(t){return!!t.__x}).forEach(function(t){t.__x.updateElements(t)})}},s=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=n,window.Spruce.start(),s(t)};export default n;
+var t=function(t){return null==t},e=function(t){return Object.getPrototypeOf(t)===Object.prototype},r=function(n,s){return Object.entries(n).forEach(function(i){var o=i[0],u=i[1];t(u)||!e(u)&&!Array.isArray(u)||(n[o]=r(u,s))}),new Proxy(n,{set:function(n,i,o){return!t(o)&&e(o)&&(o=r(o,s)),s.set(n,i,n[i]=o),!0}})},n={stores:{},subscribers:[],start:function(){try{var t=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){t.attach(),document.addEventListener("turbolinks:render",t.attach),t.stores=r(t.stores,{set:t.updateSubscribers.bind(t)})})}catch(t){return Promise.reject(t)}},attach:function(){if(!window.Alpine)throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var t=this;window.Alpine.addMagicProperty("store",function(e){return t.subscribe(e),t.stores})},store:function(t,e){return this.stores[t]||(this.stores[t]=e),this.stores[t]},reset:function(t,e){this.stores[t]=e},subscribe:function(t){return this.subscribers.includes(t)||this.subscribers.push(t),this.stores},updateSubscribers:function(){this.subscribers.filter(function(t){return!!t.__x}).forEach(function(t){t.__x.updateElements(t)})}},s=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=n,window.Spruce.start(),s(t)};export default n;
 //# sourceMappingURL=spruce.module.js.map

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/spruce.module.js.map


+ 1 - 1
dist/spruce.umd.js

@@ -1,2 +1,2 @@
-!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.spruce=t()}(this,function(){var e=function(e){return null==e},t=function(e){return Object.getPrototypeOf(e)===Object.prototype},n=function(r,s){return Object.entries(r).forEach(function(i){var o=i[0],u=i[1];e(u)||!t(u)&&!Array.isArray(u)||(r[o]=n(u,s))}),new Proxy(r,{set:function(r,i,o){return!e(o)&&t(o)&&(o=n(o,s)),s.set(r,i,r[i]=o),!0}})},r={stores:{},subscribers:[],start:function(){try{var e=this;return Promise.resolve(new Promise(function(e){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",e):e()})).then(function(){e.emit("init"),e.attach(),document.addEventListener("turbolinks:render",e.attach),e.stores=n(e.stores,{set:function(t,n,r){e.events.runWatchers(e.stores,t,n,r),e.updateSubscribers()}})})}catch(e){return Promise.reject(e)}},attach:function(){if(!window.Alpine)throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var e=this;window.Alpine.addMagicProperty("store",function(t){return e.subscribe(t),e.stores})},store:function(e,t){return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})}},s=window.deferLoadingAlpine||function(e){e()};return window.deferLoadingAlpine=function(e){window.Spruce=r,window.Spruce.start(),s(e)},r});
+!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.spruce=t()}(this,function(){var e=function(e){return null==e},t=function(e){return Object.getPrototypeOf(e)===Object.prototype},n=function(r,s){return Object.entries(r).forEach(function(i){var o=i[0],u=i[1];e(u)||!t(u)&&!Array.isArray(u)||(r[o]=n(u,s))}),new Proxy(r,{set:function(r,i,o){return!e(o)&&t(o)&&(o=n(o,s)),s.set(r,i,r[i]=o),!0}})},r={stores:{},subscribers:[],start:function(){try{var e=this;return Promise.resolve(new Promise(function(e){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",e):e()})).then(function(){e.attach(),document.addEventListener("turbolinks:render",e.attach),e.stores=n(e.stores,{set:e.updateSubscribers.bind(e)})})}catch(e){return Promise.reject(e)}},attach:function(){if(!window.Alpine)throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var e=this;window.Alpine.addMagicProperty("store",function(t){return e.subscribe(t),e.stores})},store:function(e,t){return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})}},s=window.deferLoadingAlpine||function(e){e()};return window.deferLoadingAlpine=function(e){window.Spruce=r,window.Spruce.start(),s(e)},r});
 //# sourceMappingURL=spruce.umd.js.map

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/spruce.umd.js.map


+ 1 - 7
src/index.js

@@ -8,19 +8,13 @@ const Spruce = {
 
     async start() {
         await domReady()
-
-        this.emit('init')
         
         this.attach()
 
         document.addEventListener('turbolinks:render', this.attach)
 
         this.stores = createObservable(this.stores, {
-            set: (target, key, value) => {
-                this.events.runWatchers(this.stores, target, key, value)
-
-                this.updateSubscribers()
-            }
+            set: this.updateSubscribers.bind(this)
         })
     },
 

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff