diff --git a/dist/spruce.js b/dist/spruce.js index 8242966..f203c05 100644 --- a/dist/spruce.js +++ b/dist/spruce.js @@ -1,2 +1,2 @@ -var t=function(e,r){return Object.keys(e).forEach(function(n){Object.getPrototypeOf(e[n])===Object.prototype&&(e[n]=t(e[n],r))}),new Proxy(e,{set:function(e,n,i){return"object"==typeof i&&(i=t(i,r)),r(n,e[n]=i),!0}})},e={stores:{},subscribers:[],start:function(){try{var e=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){document.querySelectorAll("[x-subscribe]").forEach(function(t){t.setAttribute("x-init",function(t){var e="$store = Spruce.subscribe($el)";return t.hasAttribute("x-init")&&(e=e+"; "+t.getAttribute("x-init")),e}(t)),t.removeAttribute("x-subscribe")}),e.stores=t(e.stores,function(t,r){e.updateSubscribers(t,r)})})}catch(t){return Promise.reject(t)}},store:function(t,e){void 0===e&&(e={}),this.stores[t]||(this.stores[t]=e)},subscribe:function(t){return this.subscribers.push(t),this.stores},updateSubscribers:function(t,e){this.subscribers.forEach(function(r){void 0!==r.__x&&(r.__x.$data.spruce=[t,e])})}},r=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=e,window.Spruce.start(),r(t)},module.exports=e; +var t=function(e,r){return Object.keys(e).forEach(function(n){Object.getPrototypeOf(e[n])!==Object.prototype||[null,void 0].includes(e[n])||(e[n]=t(e[n],r))}),new Proxy(e,{set:function(e,n,i){return"object"==typeof i&&(i=t(i,r)),r(n,e[n]=i),!0}})},e={stores:{},subscribers:[],start:function(){try{var e=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){document.querySelectorAll("[x-subscribe]").forEach(function(t){t.setAttribute("x-init",function(t){var e="$store = Spruce.subscribe($el)";return t.hasAttribute("x-init")&&(e=e+"; "+t.getAttribute("x-init")),e}(t)),t.removeAttribute("x-subscribe")}),e.stores=t(e.stores,function(t,r){e.updateSubscribers(t,r)})})}catch(t){return Promise.reject(t)}},store:function(t,e){void 0===e&&(e={}),this.stores[t]||(this.stores[t]=e)},subscribe:function(t){return this.subscribers.push(t),this.stores},updateSubscribers:function(t,e){this.subscribers.forEach(function(r){void 0!==r.__x&&(r.__x.$data.spruce=[t,e])})}},r=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=e,window.Spruce.start(),r(t)},module.exports=e; //# sourceMappingURL=spruce.js.map diff --git a/dist/spruce.js.map b/dist/spruce.js.map index 400fb27..ba9ba99 100644 --- a/dist/spruce.js.map +++ b/dist/spruce.js.map @@ -1 +1 @@ -{"version":3,"file":"spruce.js","sources":["../src/utils.js","../src/observable.js","../src/index.js"],"sourcesContent":["export const domReady = () => {\n return new Promise(resolve => {\n if (document.readyState == \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", resolve)\n } else {\n resolve()\n }\n })\n}\n\nexport const buildInitExpression = el => {\n let expression = \"$store = Spruce.subscribe($el)\"\n\n if (el.hasAttribute('x-init')) {\n expression = `${expression}; ${el.getAttribute('x-init')}`\n }\n\n return expression\n}","export const createObservable = (target, callback) => {\n Object.keys(target).forEach(key => {\n if (Object.getPrototypeOf(target[key]) === Object.prototype) {\n target[key] = createObservable(target[key], callback)\n }\n })\n\n return new Proxy(target, {\n set(target, key, value) {\n if (typeof value === 'object') {\n value = createObservable(value, callback)\n }\n\n callback(key, target[key] = value)\n\n return true\n }\n })\n}","import { domReady, buildInitExpression } from './utils'\nimport { createObservable } from './observable'\n\nconst Spruce = {\n stores: {},\n\n subscribers: [],\n\n start: async function () {\n await domReady()\n\n document.querySelectorAll('[x-subscribe]').forEach(el => {\n el.setAttribute('x-init', buildInitExpression(el))\n el.removeAttribute('x-subscribe')\n })\n\n this.stores = createObservable(this.stores, (key, value) => {\n this.updateSubscribers(key, value)\n })\n },\n\n store: function (name, state = {}) {\n if (! this.stores[name]) {\n this.stores[name] = state\n }\n },\n\n subscribe(el) {\n this.subscribers.push(el)\n\n return this.stores\n },\n\n updateSubscribers(key, value) {\n this.subscribers.forEach(el => {\n if (el.__x !== undefined) {\n el.__x.$data.spruce = [key, value]\n }\n })\n }\n}\n\nconst deferrer = window.deferLoadingAlpine || function (callback) { callback() }\n\nwindow.deferLoadingAlpine = function (callback) {\n window.Spruce = Spruce\n window.Spruce.start()\n\n deferrer(callback)\n}\n\nexport default Spruce"],"names":["const","createObservable","target","callback","Object","keys","forEach","key","getPrototypeOf","prototype","Proxy","set","value","Spruce","stores","subscribers","start","this","Promise","resolve","document","readyState","addEventListener","querySelectorAll","el","setAttribute","expression","hasAttribute","getAttribute","buildInitExpression","removeAttribute","_this","updateSubscribers","store","name","state","subscribe","push","undefined","__x","$data","spruce","deferrer","window","deferLoadingAlpine"],"mappings":"AAAOA,ICAMC,WAAoBC,EAAQC,UACrCC,OAAOC,KAAKH,GAAQI,iBAAQC,GACpBH,OAAOI,eAAeN,EAAOK,MAAUH,OAAOK,YAC9CP,EAAOK,GAAON,EAAiBC,EAAOK,GAAMJ,MAI7C,IAAIO,MAAMR,EAAQ,CACrBS,aAAIT,EAAQK,EAAKK,SACQ,iBAAVA,IACPA,EAAQX,EAAiBW,EAAOT,IAGpCA,EAASI,EAAKL,EAAOK,GAAOK,IAErB,MCZbC,EAAS,CACXC,OAAQ,GAERC,YAAa,GAEbC,2BAQIC,4BFfG,IAAIC,iBAAQC,GACY,WAAvBC,SAASC,WACTD,SAASE,iBAAiB,mBAAoBH,GAE9CA,uBEMJC,SAASG,iBAAiB,iBAAiBjB,iBAAQkB,GAC/CA,EAAGC,aAAa,kBFFOD,OAC3BE,EAAa,wCAEbF,EAAGG,aAAa,YAChBD,EAAgBA,OAAeF,EAAGI,aAAa,WAG5CF,EEL2BG,CAAoBL,IAC9CA,EAAGM,gBAAgB,mBAGlBhB,OAASb,EAAiB8B,EAAKjB,gBAASP,EAAKK,KACzCoB,kBAAkBzB,EAAKK,2CAIpCqB,MAAO,SAAUC,EAAMC,kBAAQ,IACrBlB,KAAKH,OAAOoB,UACTpB,OAAOoB,GAAQC,IAI5BC,mBAAUZ,eACDT,YAAYsB,KAAKb,GAEfP,KAAKH,QAGhBkB,2BAAkBzB,EAAKK,QACdG,YAAYT,iBAAQkB,QACNc,IAAXd,EAAGe,MACHf,EAAGe,IAAIC,MAAMC,OAAS,CAAClC,EAAKK,QAMtC8B,EAAWC,OAAOC,oBAAsB,SAAUzC,GAAYA,KAEpEwC,OAAOC,mBAAqB,SAAUzC,GAClCwC,OAAO9B,OAASA,EAChB8B,OAAO9B,OAAOG,QAEd0B,EAASvC"} \ No newline at end of file +{"version":3,"file":"spruce.js","sources":["../src/utils.js","../src/observable.js","../src/index.js"],"sourcesContent":["export const domReady = () => {\n return new Promise(resolve => {\n if (document.readyState == \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", resolve)\n } else {\n resolve()\n }\n })\n}\n\nexport const buildInitExpression = el => {\n let expression = \"$store = Spruce.subscribe($el)\"\n\n if (el.hasAttribute('x-init')) {\n expression = `${expression}; ${el.getAttribute('x-init')}`\n }\n\n return expression\n}","export const createObservable = (target, callback) => {\n Object.keys(target).forEach(key => {\n if (Object.getPrototypeOf(target[key]) === Object.prototype && ! [null, undefined].includes(target[key])) {\n target[key] = createObservable(target[key], callback)\n }\n })\n\n return new Proxy(target, {\n set(target, key, value) {\n if (typeof value === 'object') {\n value = createObservable(value, callback)\n }\n\n callback(key, target[key] = value)\n\n return true\n }\n })\n}","import { domReady, buildInitExpression } from './utils'\nimport { createObservable } from './observable'\n\nconst Spruce = {\n stores: {},\n\n subscribers: [],\n\n start: async function () {\n await domReady()\n\n document.querySelectorAll('[x-subscribe]').forEach(el => {\n el.setAttribute('x-init', buildInitExpression(el))\n el.removeAttribute('x-subscribe')\n })\n\n this.stores = createObservable(this.stores, (key, value) => {\n this.updateSubscribers(key, value)\n })\n },\n\n store: function (name, state = {}) {\n if (! this.stores[name]) {\n this.stores[name] = state\n }\n },\n\n subscribe(el) {\n this.subscribers.push(el)\n\n return this.stores\n },\n\n updateSubscribers(key, value) {\n this.subscribers.forEach(el => {\n if (el.__x !== undefined) {\n el.__x.$data.spruce = [key, value]\n }\n })\n }\n}\n\nconst deferrer = window.deferLoadingAlpine || function (callback) { callback() }\n\nwindow.deferLoadingAlpine = function (callback) {\n window.Spruce = Spruce\n window.Spruce.start()\n\n deferrer(callback)\n}\n\nexport default Spruce"],"names":["const","createObservable","target","callback","Object","keys","forEach","key","getPrototypeOf","prototype","undefined","includes","Proxy","set","value","Spruce","stores","subscribers","start","this","Promise","resolve","document","readyState","addEventListener","querySelectorAll","el","setAttribute","expression","hasAttribute","getAttribute","buildInitExpression","removeAttribute","_this","updateSubscribers","store","name","state","subscribe","push","__x","$data","spruce","deferrer","window","deferLoadingAlpine"],"mappings":"AAAOA,ICAMC,WAAoBC,EAAQC,UACrCC,OAAOC,KAAKH,GAAQI,iBAAQC,GACpBH,OAAOI,eAAeN,EAAOK,MAAUH,OAAOK,WAAe,CAAC,UAAMC,GAAWC,SAAST,EAAOK,MAC/FL,EAAOK,GAAON,EAAiBC,EAAOK,GAAMJ,MAI7C,IAAIS,MAAMV,EAAQ,CACrBW,aAAIX,EAAQK,EAAKO,SACQ,iBAAVA,IACPA,EAAQb,EAAiBa,EAAOX,IAGpCA,EAASI,EAAKL,EAAOK,GAAOO,IAErB,MCZbC,EAAS,CACXC,OAAQ,GAERC,YAAa,GAEbC,2BAQIC,4BFfG,IAAIC,iBAAQC,GACY,WAAvBC,SAASC,WACTD,SAASE,iBAAiB,mBAAoBH,GAE9CA,uBEMJC,SAASG,iBAAiB,iBAAiBnB,iBAAQoB,GAC/CA,EAAGC,aAAa,kBFFOD,OAC3BE,EAAa,wCAEbF,EAAGG,aAAa,YAChBD,EAAgBA,OAAeF,EAAGI,aAAa,WAG5CF,EEL2BG,CAAoBL,IAC9CA,EAAGM,gBAAgB,mBAGlBhB,OAASf,EAAiBgC,EAAKjB,gBAAST,EAAKO,KACzCoB,kBAAkB3B,EAAKO,2CAIpCqB,MAAO,SAAUC,EAAMC,kBAAQ,IACrBlB,KAAKH,OAAOoB,UACTpB,OAAOoB,GAAQC,IAI5BC,mBAAUZ,eACDT,YAAYsB,KAAKb,GAEfP,KAAKH,QAGhBkB,2BAAkB3B,EAAKO,QACdG,YAAYX,iBAAQoB,QACNhB,IAAXgB,EAAGc,MACHd,EAAGc,IAAIC,MAAMC,OAAS,CAACnC,EAAKO,QAMtC6B,EAAWC,OAAOC,oBAAsB,SAAU1C,GAAYA,KAEpEyC,OAAOC,mBAAqB,SAAU1C,GAClCyC,OAAO7B,OAASA,EAChB6B,OAAO7B,OAAOG,QAEdyB,EAASxC"} \ No newline at end of file diff --git a/dist/spruce.module.js b/dist/spruce.module.js index eaefe33..4b618eb 100644 --- a/dist/spruce.module.js +++ b/dist/spruce.module.js @@ -1,2 +1,2 @@ -var t=function(e,r){return Object.keys(e).forEach(function(n){Object.getPrototypeOf(e[n])===Object.prototype&&(e[n]=t(e[n],r))}),new Proxy(e,{set:function(e,n,i){return"object"==typeof i&&(i=t(i,r)),r(n,e[n]=i),!0}})},e={stores:{},subscribers:[],start:function(){try{var e=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){document.querySelectorAll("[x-subscribe]").forEach(function(t){t.setAttribute("x-init",function(t){var e="$store = Spruce.subscribe($el)";return t.hasAttribute("x-init")&&(e=e+"; "+t.getAttribute("x-init")),e}(t)),t.removeAttribute("x-subscribe")}),e.stores=t(e.stores,function(t,r){e.updateSubscribers(t,r)})})}catch(t){return Promise.reject(t)}},store:function(t,e){void 0===e&&(e={}),this.stores[t]||(this.stores[t]=e)},subscribe:function(t){return this.subscribers.push(t),this.stores},updateSubscribers:function(t,e){this.subscribers.forEach(function(r){void 0!==r.__x&&(r.__x.$data.spruce=[t,e])})}},r=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=e,window.Spruce.start(),r(t)};export default e; +var t=function(e,r){return Object.keys(e).forEach(function(n){Object.getPrototypeOf(e[n])!==Object.prototype||[null,void 0].includes(e[n])||(e[n]=t(e[n],r))}),new Proxy(e,{set:function(e,n,i){return"object"==typeof i&&(i=t(i,r)),r(n,e[n]=i),!0}})},e={stores:{},subscribers:[],start:function(){try{var e=this;return Promise.resolve(new Promise(function(t){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})).then(function(){document.querySelectorAll("[x-subscribe]").forEach(function(t){t.setAttribute("x-init",function(t){var e="$store = Spruce.subscribe($el)";return t.hasAttribute("x-init")&&(e=e+"; "+t.getAttribute("x-init")),e}(t)),t.removeAttribute("x-subscribe")}),e.stores=t(e.stores,function(t,r){e.updateSubscribers(t,r)})})}catch(t){return Promise.reject(t)}},store:function(t,e){void 0===e&&(e={}),this.stores[t]||(this.stores[t]=e)},subscribe:function(t){return this.subscribers.push(t),this.stores},updateSubscribers:function(t,e){this.subscribers.forEach(function(r){void 0!==r.__x&&(r.__x.$data.spruce=[t,e])})}},r=window.deferLoadingAlpine||function(t){t()};window.deferLoadingAlpine=function(t){window.Spruce=e,window.Spruce.start(),r(t)};export default e; //# sourceMappingURL=spruce.module.js.map diff --git a/dist/spruce.module.js.map b/dist/spruce.module.js.map index c8dae09..d8435e9 100644 --- a/dist/spruce.module.js.map +++ b/dist/spruce.module.js.map @@ -1 +1 @@ -{"version":3,"file":"spruce.module.js","sources":["../src/utils.js","../src/observable.js","../src/index.js"],"sourcesContent":["export const domReady = () => {\n return new Promise(resolve => {\n if (document.readyState == \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", resolve)\n } else {\n resolve()\n }\n })\n}\n\nexport const buildInitExpression = el => {\n let expression = \"$store = Spruce.subscribe($el)\"\n\n if (el.hasAttribute('x-init')) {\n expression = `${expression}; ${el.getAttribute('x-init')}`\n }\n\n return expression\n}","export const createObservable = (target, callback) => {\n Object.keys(target).forEach(key => {\n if (Object.getPrototypeOf(target[key]) === Object.prototype) {\n target[key] = createObservable(target[key], callback)\n }\n })\n\n return new Proxy(target, {\n set(target, key, value) {\n if (typeof value === 'object') {\n value = createObservable(value, callback)\n }\n\n callback(key, target[key] = value)\n\n return true\n }\n })\n}","import { domReady, buildInitExpression } from './utils'\nimport { createObservable } from './observable'\n\nconst Spruce = {\n stores: {},\n\n subscribers: [],\n\n start: async function () {\n await domReady()\n\n document.querySelectorAll('[x-subscribe]').forEach(el => {\n el.setAttribute('x-init', buildInitExpression(el))\n el.removeAttribute('x-subscribe')\n })\n\n this.stores = createObservable(this.stores, (key, value) => {\n this.updateSubscribers(key, value)\n })\n },\n\n store: function (name, state = {}) {\n if (! this.stores[name]) {\n this.stores[name] = state\n }\n },\n\n subscribe(el) {\n this.subscribers.push(el)\n\n return this.stores\n },\n\n updateSubscribers(key, value) {\n this.subscribers.forEach(el => {\n if (el.__x !== undefined) {\n el.__x.$data.spruce = [key, value]\n }\n })\n }\n}\n\nconst deferrer = window.deferLoadingAlpine || function (callback) { callback() }\n\nwindow.deferLoadingAlpine = function (callback) {\n window.Spruce = Spruce\n window.Spruce.start()\n\n deferrer(callback)\n}\n\nexport default Spruce"],"names":["const","createObservable","target","callback","Object","keys","forEach","key","getPrototypeOf","prototype","Proxy","set","value","Spruce","stores","subscribers","start","this","Promise","resolve","document","readyState","addEventListener","querySelectorAll","el","setAttribute","expression","hasAttribute","getAttribute","buildInitExpression","removeAttribute","_this","updateSubscribers","store","name","state","subscribe","push","undefined","__x","$data","spruce","deferrer","window","deferLoadingAlpine"],"mappings":"AAAOA,ICAMC,WAAoBC,EAAQC,UACrCC,OAAOC,KAAKH,GAAQI,iBAAQC,GACpBH,OAAOI,eAAeN,EAAOK,MAAUH,OAAOK,YAC9CP,EAAOK,GAAON,EAAiBC,EAAOK,GAAMJ,MAI7C,IAAIO,MAAMR,EAAQ,CACrBS,aAAIT,EAAQK,EAAKK,SACQ,iBAAVA,IACPA,EAAQX,EAAiBW,EAAOT,IAGpCA,EAASI,EAAKL,EAAOK,GAAOK,IAErB,MCZbC,EAAS,CACXC,OAAQ,GAERC,YAAa,GAEbC,2BAQIC,4BFfG,IAAIC,iBAAQC,GACY,WAAvBC,SAASC,WACTD,SAASE,iBAAiB,mBAAoBH,GAE9CA,uBEMJC,SAASG,iBAAiB,iBAAiBjB,iBAAQkB,GAC/CA,EAAGC,aAAa,kBFFOD,OAC3BE,EAAa,wCAEbF,EAAGG,aAAa,YAChBD,EAAgBA,OAAeF,EAAGI,aAAa,WAG5CF,EEL2BG,CAAoBL,IAC9CA,EAAGM,gBAAgB,mBAGlBhB,OAASb,EAAiB8B,EAAKjB,gBAASP,EAAKK,KACzCoB,kBAAkBzB,EAAKK,2CAIpCqB,MAAO,SAAUC,EAAMC,kBAAQ,IACrBlB,KAAKH,OAAOoB,UACTpB,OAAOoB,GAAQC,IAI5BC,mBAAUZ,eACDT,YAAYsB,KAAKb,GAEfP,KAAKH,QAGhBkB,2BAAkBzB,EAAKK,QACdG,YAAYT,iBAAQkB,QACNc,IAAXd,EAAGe,MACHf,EAAGe,IAAIC,MAAMC,OAAS,CAAClC,EAAKK,QAMtC8B,EAAWC,OAAOC,oBAAsB,SAAUzC,GAAYA,KAEpEwC,OAAOC,mBAAqB,SAAUzC,GAClCwC,OAAO9B,OAASA,EAChB8B,OAAO9B,OAAOG,QAEd0B,EAASvC"} \ No newline at end of file +{"version":3,"file":"spruce.module.js","sources":["../src/utils.js","../src/observable.js","../src/index.js"],"sourcesContent":["export const domReady = () => {\n return new Promise(resolve => {\n if (document.readyState == \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", resolve)\n } else {\n resolve()\n }\n })\n}\n\nexport const buildInitExpression = el => {\n let expression = \"$store = Spruce.subscribe($el)\"\n\n if (el.hasAttribute('x-init')) {\n expression = `${expression}; ${el.getAttribute('x-init')}`\n }\n\n return expression\n}","export const createObservable = (target, callback) => {\n Object.keys(target).forEach(key => {\n if (Object.getPrototypeOf(target[key]) === Object.prototype && ! [null, undefined].includes(target[key])) {\n target[key] = createObservable(target[key], callback)\n }\n })\n\n return new Proxy(target, {\n set(target, key, value) {\n if (typeof value === 'object') {\n value = createObservable(value, callback)\n }\n\n callback(key, target[key] = value)\n\n return true\n }\n })\n}","import { domReady, buildInitExpression } from './utils'\nimport { createObservable } from './observable'\n\nconst Spruce = {\n stores: {},\n\n subscribers: [],\n\n start: async function () {\n await domReady()\n\n document.querySelectorAll('[x-subscribe]').forEach(el => {\n el.setAttribute('x-init', buildInitExpression(el))\n el.removeAttribute('x-subscribe')\n })\n\n this.stores = createObservable(this.stores, (key, value) => {\n this.updateSubscribers(key, value)\n })\n },\n\n store: function (name, state = {}) {\n if (! this.stores[name]) {\n this.stores[name] = state\n }\n },\n\n subscribe(el) {\n this.subscribers.push(el)\n\n return this.stores\n },\n\n updateSubscribers(key, value) {\n this.subscribers.forEach(el => {\n if (el.__x !== undefined) {\n el.__x.$data.spruce = [key, value]\n }\n })\n }\n}\n\nconst deferrer = window.deferLoadingAlpine || function (callback) { callback() }\n\nwindow.deferLoadingAlpine = function (callback) {\n window.Spruce = Spruce\n window.Spruce.start()\n\n deferrer(callback)\n}\n\nexport default Spruce"],"names":["const","createObservable","target","callback","Object","keys","forEach","key","getPrototypeOf","prototype","undefined","includes","Proxy","set","value","Spruce","stores","subscribers","start","this","Promise","resolve","document","readyState","addEventListener","querySelectorAll","el","setAttribute","expression","hasAttribute","getAttribute","buildInitExpression","removeAttribute","_this","updateSubscribers","store","name","state","subscribe","push","__x","$data","spruce","deferrer","window","deferLoadingAlpine"],"mappings":"AAAOA,ICAMC,WAAoBC,EAAQC,UACrCC,OAAOC,KAAKH,GAAQI,iBAAQC,GACpBH,OAAOI,eAAeN,EAAOK,MAAUH,OAAOK,WAAe,CAAC,UAAMC,GAAWC,SAAST,EAAOK,MAC/FL,EAAOK,GAAON,EAAiBC,EAAOK,GAAMJ,MAI7C,IAAIS,MAAMV,EAAQ,CACrBW,aAAIX,EAAQK,EAAKO,SACQ,iBAAVA,IACPA,EAAQb,EAAiBa,EAAOX,IAGpCA,EAASI,EAAKL,EAAOK,GAAOO,IAErB,MCZbC,EAAS,CACXC,OAAQ,GAERC,YAAa,GAEbC,2BAQIC,4BFfG,IAAIC,iBAAQC,GACY,WAAvBC,SAASC,WACTD,SAASE,iBAAiB,mBAAoBH,GAE9CA,uBEMJC,SAASG,iBAAiB,iBAAiBnB,iBAAQoB,GAC/CA,EAAGC,aAAa,kBFFOD,OAC3BE,EAAa,wCAEbF,EAAGG,aAAa,YAChBD,EAAgBA,OAAeF,EAAGI,aAAa,WAG5CF,EEL2BG,CAAoBL,IAC9CA,EAAGM,gBAAgB,mBAGlBhB,OAASf,EAAiBgC,EAAKjB,gBAAST,EAAKO,KACzCoB,kBAAkB3B,EAAKO,2CAIpCqB,MAAO,SAAUC,EAAMC,kBAAQ,IACrBlB,KAAKH,OAAOoB,UACTpB,OAAOoB,GAAQC,IAI5BC,mBAAUZ,eACDT,YAAYsB,KAAKb,GAEfP,KAAKH,QAGhBkB,2BAAkB3B,EAAKO,QACdG,YAAYX,iBAAQoB,QACNhB,IAAXgB,EAAGc,MACHd,EAAGc,IAAIC,MAAMC,OAAS,CAACnC,EAAKO,QAMtC6B,EAAWC,OAAOC,oBAAsB,SAAU1C,GAAYA,KAEpEyC,OAAOC,mBAAqB,SAAU1C,GAClCyC,OAAO7B,OAASA,EAChB6B,OAAO7B,OAAOG,QAEdyB,EAASxC"} \ No newline at end of file diff --git a/dist/spruce.umd.js b/dist/spruce.umd.js index a062000..3502b94 100644 --- a/dist/spruce.umd.js +++ b/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(t,r){return Object.keys(t).forEach(function(n){Object.getPrototypeOf(t[n])===Object.prototype&&(t[n]=e(t[n],r))}),new Proxy(t,{set:function(t,n,o){return"object"==typeof o&&(o=e(o,r)),r(n,t[n]=o),!0}})},t={stores:{},subscribers:[],start:function(){try{var t=this;return Promise.resolve(new Promise(function(e){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",e):e()})).then(function(){document.querySelectorAll("[x-subscribe]").forEach(function(e){e.setAttribute("x-init",function(e){var t="$store = Spruce.subscribe($el)";return e.hasAttribute("x-init")&&(t=t+"; "+e.getAttribute("x-init")),t}(e)),e.removeAttribute("x-subscribe")}),t.stores=e(t.stores,function(e,r){t.updateSubscribers(e,r)})})}catch(e){return Promise.reject(e)}},store:function(e,t){void 0===t&&(t={}),this.stores[e]||(this.stores[e]=t)},subscribe:function(e){return this.subscribers.push(e),this.stores},updateSubscribers:function(e,t){this.subscribers.forEach(function(r){void 0!==r.__x&&(r.__x.$data.spruce=[e,t])})}},r=window.deferLoadingAlpine||function(e){e()};return window.deferLoadingAlpine=function(e){window.Spruce=t,window.Spruce.start(),r(e)},t}); +!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(t,n){return Object.keys(t).forEach(function(r){Object.getPrototypeOf(t[r])!==Object.prototype||[null,void 0].includes(t[r])||(t[r]=e(t[r],n))}),new Proxy(t,{set:function(t,r,i){return"object"==typeof i&&(i=e(i,n)),n(r,t[r]=i),!0}})},t={stores:{},subscribers:[],start:function(){try{var t=this;return Promise.resolve(new Promise(function(e){"loading"==document.readyState?document.addEventListener("DOMContentLoaded",e):e()})).then(function(){document.querySelectorAll("[x-subscribe]").forEach(function(e){e.setAttribute("x-init",function(e){var t="$store = Spruce.subscribe($el)";return e.hasAttribute("x-init")&&(t=t+"; "+e.getAttribute("x-init")),t}(e)),e.removeAttribute("x-subscribe")}),t.stores=e(t.stores,function(e,n){t.updateSubscribers(e,n)})})}catch(e){return Promise.reject(e)}},store:function(e,t){void 0===t&&(t={}),this.stores[e]||(this.stores[e]=t)},subscribe:function(e){return this.subscribers.push(e),this.stores},updateSubscribers:function(e,t){this.subscribers.forEach(function(n){void 0!==n.__x&&(n.__x.$data.spruce=[e,t])})}},n=window.deferLoadingAlpine||function(e){e()};return window.deferLoadingAlpine=function(e){window.Spruce=t,window.Spruce.start(),n(e)},t}); //# sourceMappingURL=spruce.umd.js.map diff --git a/dist/spruce.umd.js.map b/dist/spruce.umd.js.map index 3ed6eb5..5d88123 100644 --- a/dist/spruce.umd.js.map +++ b/dist/spruce.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"spruce.umd.js","sources":["../src/utils.js","../src/observable.js","../src/index.js"],"sourcesContent":["export const domReady = () => {\n return new Promise(resolve => {\n if (document.readyState == \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", resolve)\n } else {\n resolve()\n }\n })\n}\n\nexport const buildInitExpression = el => {\n let expression = \"$store = Spruce.subscribe($el)\"\n\n if (el.hasAttribute('x-init')) {\n expression = `${expression}; ${el.getAttribute('x-init')}`\n }\n\n return expression\n}","export const createObservable = (target, callback) => {\n Object.keys(target).forEach(key => {\n if (Object.getPrototypeOf(target[key]) === Object.prototype) {\n target[key] = createObservable(target[key], callback)\n }\n })\n\n return new Proxy(target, {\n set(target, key, value) {\n if (typeof value === 'object') {\n value = createObservable(value, callback)\n }\n\n callback(key, target[key] = value)\n\n return true\n }\n })\n}","import { domReady, buildInitExpression } from './utils'\nimport { createObservable } from './observable'\n\nconst Spruce = {\n stores: {},\n\n subscribers: [],\n\n start: async function () {\n await domReady()\n\n document.querySelectorAll('[x-subscribe]').forEach(el => {\n el.setAttribute('x-init', buildInitExpression(el))\n el.removeAttribute('x-subscribe')\n })\n\n this.stores = createObservable(this.stores, (key, value) => {\n this.updateSubscribers(key, value)\n })\n },\n\n store: function (name, state = {}) {\n if (! this.stores[name]) {\n this.stores[name] = state\n }\n },\n\n subscribe(el) {\n this.subscribers.push(el)\n\n return this.stores\n },\n\n updateSubscribers(key, value) {\n this.subscribers.forEach(el => {\n if (el.__x !== undefined) {\n el.__x.$data.spruce = [key, value]\n }\n })\n }\n}\n\nconst deferrer = window.deferLoadingAlpine || function (callback) { callback() }\n\nwindow.deferLoadingAlpine = function (callback) {\n window.Spruce = Spruce\n window.Spruce.start()\n\n deferrer(callback)\n}\n\nexport default Spruce"],"names":["const","createObservable","target","callback","Object","keys","forEach","key","getPrototypeOf","prototype","Proxy","set","value","Spruce","stores","subscribers","start","this","Promise","resolve","document","readyState","addEventListener","querySelectorAll","el","setAttribute","expression","hasAttribute","getAttribute","buildInitExpression","removeAttribute","_this","updateSubscribers","store","name","state","subscribe","push","undefined","__x","$data","spruce","deferrer","window","deferLoadingAlpine"],"mappings":"qKAAOA,ICAMC,WAAoBC,EAAQC,UACrCC,OAAOC,KAAKH,GAAQI,iBAAQC,GACpBH,OAAOI,eAAeN,EAAOK,MAAUH,OAAOK,YAC9CP,EAAOK,GAAON,EAAiBC,EAAOK,GAAMJ,MAI7C,IAAIO,MAAMR,EAAQ,CACrBS,aAAIT,EAAQK,EAAKK,SACQ,iBAAVA,IACPA,EAAQX,EAAiBW,EAAOT,IAGpCA,EAASI,EAAKL,EAAOK,GAAOK,IAErB,MCZbC,EAAS,CACXC,OAAQ,GAERC,YAAa,GAEbC,2BAQIC,4BFfG,IAAIC,iBAAQC,GACY,WAAvBC,SAASC,WACTD,SAASE,iBAAiB,mBAAoBH,GAE9CA,uBEMJC,SAASG,iBAAiB,iBAAiBjB,iBAAQkB,GAC/CA,EAAGC,aAAa,kBFFOD,OAC3BE,EAAa,wCAEbF,EAAGG,aAAa,YAChBD,EAAgBA,OAAeF,EAAGI,aAAa,WAG5CF,EEL2BG,CAAoBL,IAC9CA,EAAGM,gBAAgB,mBAGlBhB,OAASb,EAAiB8B,EAAKjB,gBAASP,EAAKK,KACzCoB,kBAAkBzB,EAAKK,2CAIpCqB,MAAO,SAAUC,EAAMC,kBAAQ,IACrBlB,KAAKH,OAAOoB,UACTpB,OAAOoB,GAAQC,IAI5BC,mBAAUZ,eACDT,YAAYsB,KAAKb,GAEfP,KAAKH,QAGhBkB,2BAAkBzB,EAAKK,QACdG,YAAYT,iBAAQkB,QACNc,IAAXd,EAAGe,MACHf,EAAGe,IAAIC,MAAMC,OAAS,CAAClC,EAAKK,QAMtC8B,EAAWC,OAAOC,oBAAsB,SAAUzC,GAAYA,YAEpEwC,OAAOC,mBAAqB,SAAUzC,GAClCwC,OAAO9B,OAASA,EAChB8B,OAAO9B,OAAOG,QAEd0B,EAASvC"} \ No newline at end of file +{"version":3,"file":"spruce.umd.js","sources":["../src/utils.js","../src/observable.js","../src/index.js"],"sourcesContent":["export const domReady = () => {\n return new Promise(resolve => {\n if (document.readyState == \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", resolve)\n } else {\n resolve()\n }\n })\n}\n\nexport const buildInitExpression = el => {\n let expression = \"$store = Spruce.subscribe($el)\"\n\n if (el.hasAttribute('x-init')) {\n expression = `${expression}; ${el.getAttribute('x-init')}`\n }\n\n return expression\n}","export const createObservable = (target, callback) => {\n Object.keys(target).forEach(key => {\n if (Object.getPrototypeOf(target[key]) === Object.prototype && ! [null, undefined].includes(target[key])) {\n target[key] = createObservable(target[key], callback)\n }\n })\n\n return new Proxy(target, {\n set(target, key, value) {\n if (typeof value === 'object') {\n value = createObservable(value, callback)\n }\n\n callback(key, target[key] = value)\n\n return true\n }\n })\n}","import { domReady, buildInitExpression } from './utils'\nimport { createObservable } from './observable'\n\nconst Spruce = {\n stores: {},\n\n subscribers: [],\n\n start: async function () {\n await domReady()\n\n document.querySelectorAll('[x-subscribe]').forEach(el => {\n el.setAttribute('x-init', buildInitExpression(el))\n el.removeAttribute('x-subscribe')\n })\n\n this.stores = createObservable(this.stores, (key, value) => {\n this.updateSubscribers(key, value)\n })\n },\n\n store: function (name, state = {}) {\n if (! this.stores[name]) {\n this.stores[name] = state\n }\n },\n\n subscribe(el) {\n this.subscribers.push(el)\n\n return this.stores\n },\n\n updateSubscribers(key, value) {\n this.subscribers.forEach(el => {\n if (el.__x !== undefined) {\n el.__x.$data.spruce = [key, value]\n }\n })\n }\n}\n\nconst deferrer = window.deferLoadingAlpine || function (callback) { callback() }\n\nwindow.deferLoadingAlpine = function (callback) {\n window.Spruce = Spruce\n window.Spruce.start()\n\n deferrer(callback)\n}\n\nexport default Spruce"],"names":["const","createObservable","target","callback","Object","keys","forEach","key","getPrototypeOf","prototype","undefined","includes","Proxy","set","value","Spruce","stores","subscribers","start","this","Promise","resolve","document","readyState","addEventListener","querySelectorAll","el","setAttribute","expression","hasAttribute","getAttribute","buildInitExpression","removeAttribute","_this","updateSubscribers","store","name","state","subscribe","push","__x","$data","spruce","deferrer","window","deferLoadingAlpine"],"mappings":"qKAAOA,ICAMC,WAAoBC,EAAQC,UACrCC,OAAOC,KAAKH,GAAQI,iBAAQC,GACpBH,OAAOI,eAAeN,EAAOK,MAAUH,OAAOK,WAAe,CAAC,UAAMC,GAAWC,SAAST,EAAOK,MAC/FL,EAAOK,GAAON,EAAiBC,EAAOK,GAAMJ,MAI7C,IAAIS,MAAMV,EAAQ,CACrBW,aAAIX,EAAQK,EAAKO,SACQ,iBAAVA,IACPA,EAAQb,EAAiBa,EAAOX,IAGpCA,EAASI,EAAKL,EAAOK,GAAOO,IAErB,MCZbC,EAAS,CACXC,OAAQ,GAERC,YAAa,GAEbC,2BAQIC,4BFfG,IAAIC,iBAAQC,GACY,WAAvBC,SAASC,WACTD,SAASE,iBAAiB,mBAAoBH,GAE9CA,uBEMJC,SAASG,iBAAiB,iBAAiBnB,iBAAQoB,GAC/CA,EAAGC,aAAa,kBFFOD,OAC3BE,EAAa,wCAEbF,EAAGG,aAAa,YAChBD,EAAgBA,OAAeF,EAAGI,aAAa,WAG5CF,EEL2BG,CAAoBL,IAC9CA,EAAGM,gBAAgB,mBAGlBhB,OAASf,EAAiBgC,EAAKjB,gBAAST,EAAKO,KACzCoB,kBAAkB3B,EAAKO,2CAIpCqB,MAAO,SAAUC,EAAMC,kBAAQ,IACrBlB,KAAKH,OAAOoB,UACTpB,OAAOoB,GAAQC,IAI5BC,mBAAUZ,eACDT,YAAYsB,KAAKb,GAEfP,KAAKH,QAGhBkB,2BAAkB3B,EAAKO,QACdG,YAAYX,iBAAQoB,QACNhB,IAAXgB,EAAGc,MACHd,EAAGc,IAAIC,MAAMC,OAAS,CAACnC,EAAKO,QAMtC6B,EAAWC,OAAOC,oBAAsB,SAAU1C,GAAYA,YAEpEyC,OAAOC,mBAAqB,SAAU1C,GAClCyC,OAAO7B,OAASA,EAChB6B,OAAO7B,OAAOG,QAEdyB,EAASxC"} \ No newline at end of file diff --git a/src/observable.js b/src/observable.js index 9c1090c..95e91ce 100644 --- a/src/observable.js +++ b/src/observable.js @@ -1,6 +1,6 @@ export const createObservable = (target, callback) => { Object.keys(target).forEach(key => { - if (Object.getPrototypeOf(target[key]) === Object.prototype) { + if (Object.getPrototypeOf(target[key]) === Object.prototype && ! [null, undefined].includes(target[key])) { target[key] = createObservable(target[key], callback) } })