callbag-state
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -1,1 +0,1 @@ | ||
var callbagState=function(t){"use strict";function e(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(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}function o(t){return!t||!t.subs}function u(t,e,r){n(r).forEach((function(n){r.indexOf(n)>=0&&n(t,e)}))}function a(t){return null==t||"number"==typeof t||"string"==typeof t||"boolean"==typeof t||t instanceof Date}function i(t,e){if(t!==e){if(!a(t)&&!a(e)){var n={subs:{}},r=new Set,o=!1;for(var u in t){r.add(u);var f=i(t[u],e[u]);f&&(n.subs[u]=f,o=!0)}for(var c in e)r.has(c)||(n.subs[c]=i(t[c],e[c]),o=!0);return o?n:void 0}return t instanceof Date&&e instanceof Date&&+t!=+e||t!==e?{from:t,to:e}:void 0}}function f(t){if(o(t.trace)&&t.trace){var e=i(t.trace.from,t.trace.to);if(e)return{value:t.value,trace:e}}return t}function c(t,n,r){var a=[],i=t,s=void 0,l=function(t){u(2,t,a),a.length=0,s=void 0},v=function(t,e){if(0===t){var r=e;a.push(r),r(0,(function(t){if(2===t){var e=a.indexOf(r);e>=0&&a.splice(e,1),0===a.length&&s&&s(2)}})),1===a.length&&n(0,(function(t,e){if(0===t)s=e;else if(1===t){var n=f(e);n.value!==i&&(i=n.value),u(1,n,a)}else 2===t&&l(e)}))}},d=function(t,e){if(0===t){var n=e;v(0,(function(t,e){0===t?(n(0,e),n(1,i)):1===t?n(1,e.value):2===t&&n(2,e)}))}else 1===t?r(1,{value:e,trace:{from:i,to:e}}):2===t&&(r(2,e),l(e))};return d.get=function(){return i},d.set=function(t){return d(1,t)},d.clear=function(){return d(2)},d.downstream=function(){return v},d.upstream=function(){return r},d.sub=function(t){var n,u,a,f=c(i?i[t]:void 0,(n=v,u=t,a=function(){return f.get()},function(t,e){if(0===t){var r=void 0;n(0,(function(t,n){var i;if(0===t)r=n;else if(1===t){var f=n,c=f.value?f.value[u]:void 0;(o(f.trace)&&c!==a()||!o(f.trace)&&u in(null===(i=f.trace)||void 0===i?void 0:i.subs))&&e(1,{value:c,trace:o(f.trace)?void 0:f.trace.subs[u]})}else 2===t&&e(2,n)})),e(0,(function(t,e){r&&r(t,e)}))}}),function(t,n,r){return function(o,u){if(1===o){var a=u;r&&(r[n]=a.value),t(1,{value:r,trace:{subs:e({},n,a.trace)}})}else 2===o&&u&&t(2,u)}}(r,t,i));return f},d}function s(t){var e,n=(e=void 0,function(t,n){0===t?e||(e=n)(0,(function(t){2===t&&(e=void 0)})):e&&(e(t,n),2===t&&(e=void 0))});return c(t,n,n)}return t._Data=1,t._End=2,t._Start=0,t.broadcast=u,t.change=function(t,e){var n=i(t,e);if(n)return{value:e,trace:n}},t.default=s,t.isLeaf=o,t.isState=function(t){return t&&"function"==typeof t&&2===t.length&&t.get&&"function"==typeof t.get&&0===t.get.length&&t.set&&"function"==typeof t.set&&1===t.set.length&&t.clear&&"function"==typeof t.clear&&0===t.clear.length&&t.downstream&&"function"==typeof t.downstream&&0===t.downstream.length&&t.upstream&&"function"==typeof t.upstream&&0===t.upstream.length&&t.sub&&"function"==typeof t.sub&&1===t.sub.length},t.makeState=c,t.postTrace=f,t.state=s,t.trace=i,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); | ||
var callbagState=function(t){"use strict";function e(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(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}function o(t){return!t||!t.subs}function u(t,e,r){n(r).forEach((function(n){r.indexOf(n)>=0&&n(t,e)}))}function a(t){return null==t||"number"==typeof t||"string"==typeof t||"boolean"==typeof t||t instanceof Date}function i(t,e){if(t!==e){if(!a(t)&&!a(e)){var n={subs:{}},r=new Set,o=!1;for(var u in t){r.add(u);var f=i(t[u],e[u]);f&&(n.subs[u]=f,o=!0)}for(var c in e)r.has(c)||(n.subs[c]=i(t[c],e[c]),o=!0);return o?n:void 0}return t instanceof Date&&e instanceof Date&&+t!=+e||t!==e?{from:t,to:e}:void 0}}function f(t){if(o(t.trace)&&t.trace){var e=i(t.trace.from,t.trace.to);if(e)return{value:t.value,trace:e}}return t}function c(t,n,r){var a=[],i=t,s=void 0;n(0,(function(t,e){if(0===t)s=e;else if(1===t){var n=f(e);n.value!==i&&(i=n.value),u(1,n,a)}else 2===t&&l(e)}));var l=function(t){u(2,t,a),a.length=0,s&&(s(2,t),s=void 0)},v=function(t,e){if(0===t){var n=e;a.push(n),n(0,(function(t){if(2===t){var e=a.indexOf(n);e>=0&&a.splice(e,1)}}))}},d=function(t,e){if(0===t){var n=e;v(0,(function(t,e){0===t?(n(0,e),n(1,i)):1===t?n(1,e.value):2===t&&n(2,e)}))}else 1===t?r(1,{value:e,trace:{from:i,to:e}}):2===t&&(r(2,e),l(e))};return d.get=function(){return i},d.set=function(t){return d(1,t)},d.clear=function(){return d(2)},d.downstream=function(){return v},d.upstream=function(){return r},d.sub=function(t){var n,u,a,f=c(i?i[t]:void 0,(n=v,u=t,a=function(){return f.get()},function(t,e){if(0===t){var r=void 0;n(0,(function(t,n){var i;if(0===t)r=n;else if(1===t){var f=n,c=f.value?f.value[u]:void 0;(o(f.trace)&&c!==a()||!o(f.trace)&&u in(null===(i=f.trace)||void 0===i?void 0:i.subs))&&e(1,{value:c,trace:o(f.trace)?void 0:f.trace.subs[u]})}else 2===t&&e(2,n)})),e(0,(function(t,e){r&&r(t,e)}))}}),function(t,n,r){return function(o,u){if(1===o){var a=u;r&&(r[n]=a.value),t(1,{value:r,trace:{subs:e({},n,a.trace)}})}else 2===o&&u&&t(2,u)}}(r,t,i));return f},d}function s(t){var e,n=(e=void 0,function(t,n){0===t?e||(e=n)(0,(function(t){2===t&&(e=void 0)})):e&&(e(t,n),2===t&&(e=void 0))});return c(t,n,n)}return t._Data=1,t._End=2,t._Start=0,t.broadcast=u,t.change=function(t,e){var n=i(t,e);if(n)return{value:e,trace:n}},t.default=s,t.isLeaf=o,t.isState=function(t){return t&&"function"==typeof t&&2===t.length&&t.get&&"function"==typeof t.get&&0===t.get.length&&t.set&&"function"==typeof t.set&&1===t.set.length&&t.clear&&"function"==typeof t.clear&&0===t.clear.length&&t.downstream&&"function"==typeof t.downstream&&0===t.downstream.length&&t.upstream&&"function"==typeof t.upstream&&0===t.upstream.length&&t.sub&&"function"==typeof t.sub&&1===t.sub.length},t.makeState=c,t.postTrace=f,t.state=s,t.trace=i,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); |
@@ -1,1 +0,1 @@ | ||
var callbagState=function(t){"use strict";function e(t){return!t||!t.subs}function n(t,e,n){[...n].forEach((o=>{n.indexOf(o)>=0&&o(t,e)}))}function o(t){return null==t||"number"==typeof t||"string"==typeof t||"boolean"==typeof t||t instanceof Date}function r(t,e){if(t!==e){if(!o(t)&&!o(e)){const n={subs:{}},o=new Set;let a=!1;for(const u in t){o.add(u);const s=r(t[u],e[u]);s&&(n.subs[u]=s,a=!0)}for(const u in e)o.has(u)||(n.subs[u]=r(t[u],e[u]),a=!0);return a?n:void 0}return t instanceof Date&&e instanceof Date&&+t!=+e||t!==e?{from:t,to:e}:void 0}}function a(t){if(e(t.trace)&&t.trace){const e=r(t.trace.from,t.trace.to);if(e)return{value:t.value,trace:e}}return t}function u(t,o,r){const s=[];let c=t,i=void 0;const f=t=>{n(2,t,s),s.length=0,i=void 0},l=(t,e)=>{if(0===t){const t=e;s.push(t),t(0,(e=>{if(2===e){const e=s.indexOf(t);e>=0&&s.splice(e,1),0===s.length&&i&&i(2)}})),1===s.length&&o(0,((t,e)=>{if(0===t)i=e;else if(1===t){const t=a(e);t.value!==c&&(c=t.value),n(1,t,s)}else 2===t&&f(e)}))}},v=(t,e)=>{if(0===t){const t=e;l(0,((e,n)=>{0===e?(t(0,n),t(1,c)):1===e?t(1,n.value):2===e&&t(2,n)}))}else 1===t?r(1,{value:e,trace:{from:c,to:e}}):2===t&&(r(2,e),f(e))};return v.get=()=>c,v.set=t=>v(1,t),v.clear=()=>v(2),v.downstream=()=>l,v.upstream=()=>r,v.sub=t=>{const n=u(c?c[t]:void 0,(o=l,a=t,s=()=>n.get(),(t,n)=>{if(0!==t)return;let r=void 0;o(0,((t,o)=>{var u;if(0===t)r=o;else if(1===t){const t=o,r=t.value?t.value[a]:void 0;(e(t.trace)&&r!==s()||!e(t.trace)&&a in(null===(u=t.trace)||void 0===u?void 0:u.subs))&&n(1,{value:r,trace:e(t.trace)?void 0:t.trace.subs[a]})}else 2===t&&n(2,o)})),n(0,((t,e)=>{r&&r(t,e)}))}),function(t,e,n){return(o,r)=>{if(1===o){const o=r;n&&(n[e]=o.value),t(1,{value:n,trace:{subs:{[e]:o.trace}}})}else 2===o&&r&&t(2,r)}}(r,t,c));var o,a,s;return n},v}function s(t){const e=function(){let t=void 0;return(e,n)=>{0===e?t||(t=n,t(0,(e=>{2===e&&(t=void 0)}))):t&&(t(e,n),2===e&&(t=void 0))}}();return u(t,e,e)}return t._Data=1,t._End=2,t._Start=0,t.broadcast=n,t.change=function(t,e){const n=r(t,e);if(n)return{value:e,trace:n}},t.default=s,t.isLeaf=e,t.isState=function(t){return t&&"function"==typeof t&&2===t.length&&t.get&&"function"==typeof t.get&&0===t.get.length&&t.set&&"function"==typeof t.set&&1===t.set.length&&t.clear&&"function"==typeof t.clear&&0===t.clear.length&&t.downstream&&"function"==typeof t.downstream&&0===t.downstream.length&&t.upstream&&"function"==typeof t.upstream&&0===t.upstream.length&&t.sub&&"function"==typeof t.sub&&1===t.sub.length},t.makeState=u,t.postTrace=a,t.state=s,t.trace=r,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); | ||
var callbagState=function(t){"use strict";function e(t){return!t||!t.subs}function n(t,e,n){[...n].forEach((o=>{n.indexOf(o)>=0&&o(t,e)}))}function o(t){return null==t||"number"==typeof t||"string"==typeof t||"boolean"==typeof t||t instanceof Date}function r(t,e){if(t!==e){if(!o(t)&&!o(e)){const n={subs:{}},o=new Set;let a=!1;for(const u in t){o.add(u);const s=r(t[u],e[u]);s&&(n.subs[u]=s,a=!0)}for(const u in e)o.has(u)||(n.subs[u]=r(t[u],e[u]),a=!0);return a?n:void 0}return t instanceof Date&&e instanceof Date&&+t!=+e||t!==e?{from:t,to:e}:void 0}}function a(t){if(e(t.trace)&&t.trace){const e=r(t.trace.from,t.trace.to);if(e)return{value:t.value,trace:e}}return t}function u(t,o,r){const s=[];let c=t,i=void 0;o(0,((t,e)=>{if(0===t)i=e;else if(1===t){const t=a(e);t.value!==c&&(c=t.value),n(1,t,s)}else 2===t&&f(e)}));const f=t=>{n(2,t,s),s.length=0,i&&(i(2,t),i=void 0)},l=(t,e)=>{if(0===t){const t=e;s.push(t),t(0,(e=>{if(2===e){const e=s.indexOf(t);e>=0&&s.splice(e,1)}}))}},v=(t,e)=>{if(0===t){const t=e;l(0,((e,n)=>{0===e?(t(0,n),t(1,c)):1===e?t(1,n.value):2===e&&t(2,n)}))}else 1===t?r(1,{value:e,trace:{from:c,to:e}}):2===t&&(r(2,e),f(e))};return v.get=()=>c,v.set=t=>v(1,t),v.clear=()=>v(2),v.downstream=()=>l,v.upstream=()=>r,v.sub=t=>{const n=u(c?c[t]:void 0,(o=l,a=t,s=()=>n.get(),(t,n)=>{if(0!==t)return;let r=void 0;o(0,((t,o)=>{var u;if(0===t)r=o;else if(1===t){const t=o,r=t.value?t.value[a]:void 0;(e(t.trace)&&r!==s()||!e(t.trace)&&a in(null===(u=t.trace)||void 0===u?void 0:u.subs))&&n(1,{value:r,trace:e(t.trace)?void 0:t.trace.subs[a]})}else 2===t&&n(2,o)})),n(0,((t,e)=>{r&&r(t,e)}))}),function(t,e,n){return(o,r)=>{if(1===o){const o=r;n&&(n[e]=o.value),t(1,{value:n,trace:{subs:{[e]:o.trace}}})}else 2===o&&r&&t(2,r)}}(r,t,c));var o,a,s;return n},v}function s(t){const e=function(){let t=void 0;return(e,n)=>{0===e?t||(t=n,t(0,(e=>{2===e&&(t=void 0)}))):t&&(t(e,n),2===e&&(t=void 0))}}();return u(t,e,e)}return t._Data=1,t._End=2,t._Start=0,t.broadcast=n,t.change=function(t,e){const n=r(t,e);if(n)return{value:e,trace:n}},t.default=s,t.isLeaf=e,t.isState=function(t){return t&&"function"==typeof t&&2===t.length&&t.get&&"function"==typeof t.get&&0===t.get.length&&t.set&&"function"==typeof t.set&&1===t.set.length&&t.clear&&"function"==typeof t.clear&&0===t.clear.length&&t.downstream&&"function"==typeof t.downstream&&0===t.downstream.length&&t.upstream&&"function"==typeof t.upstream&&0===t.upstream.length&&t.sub&&"function"==typeof t.sub&&1===t.sub.length},t.makeState=u,t.postTrace=a,t.state=s,t.trace=r,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); |
@@ -12,6 +12,24 @@ "use strict"; | ||
var talkback = undefined; | ||
downstream(types_1._Start, function (t, _m) { | ||
if (t === types_1._Start) { | ||
talkback = _m; | ||
} | ||
else if (t === types_1._Data) { | ||
var change = trace_1.postTrace(_m); | ||
if (change.value !== value) { | ||
value = change.value; | ||
} | ||
broadcast_1.broadcast(types_1._Data, change, sinks); | ||
} | ||
else if (t === types_1._End) { | ||
terminate(_m); | ||
} | ||
}); | ||
var terminate = function (err) { | ||
broadcast_1.broadcast(types_1._End, err, sinks); | ||
sinks.length = 0; | ||
talkback = undefined; | ||
if (talkback) { | ||
talkback(types_1._End, err); | ||
talkback = undefined; | ||
} | ||
}; | ||
@@ -28,24 +46,4 @@ var _downstream = function (type, m) { | ||
} | ||
if (sinks.length === 0 && talkback) { | ||
talkback(types_1._End); | ||
} | ||
} | ||
}); | ||
if (sinks.length === 1) { | ||
downstream(types_1._Start, function (t, _m) { | ||
if (t === types_1._Start) { | ||
talkback = _m; | ||
} | ||
else if (t === types_1._Data) { | ||
var change = trace_1.postTrace(_m); | ||
if (change.value !== value) { | ||
value = change.value; | ||
} | ||
broadcast_1.broadcast(types_1._Data, change, sinks); | ||
} | ||
else if (t === types_1._End) { | ||
terminate(_m); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -52,0 +50,0 @@ }; |
@@ -9,6 +9,24 @@ import { subDownstream, subUpstream } from './substream'; | ||
let talkback = undefined; | ||
downstream(_Start, (t, _m) => { | ||
if (t === _Start) { | ||
talkback = _m; | ||
} | ||
else if (t === _Data) { | ||
const change = postTrace(_m); | ||
if (change.value !== value) { | ||
value = change.value; | ||
} | ||
broadcast(_Data, change, sinks); | ||
} | ||
else if (t === _End) { | ||
terminate(_m); | ||
} | ||
}); | ||
const terminate = (err) => { | ||
broadcast(_End, err, sinks); | ||
sinks.length = 0; | ||
talkback = undefined; | ||
if (talkback) { | ||
talkback(_End, err); | ||
talkback = undefined; | ||
} | ||
}; | ||
@@ -25,24 +43,4 @@ const _downstream = (type, m) => { | ||
} | ||
if (sinks.length === 0 && talkback) { | ||
talkback(_End); | ||
} | ||
} | ||
}); | ||
if (sinks.length === 1) { | ||
downstream(_Start, (t, _m) => { | ||
if (t === _Start) { | ||
talkback = _m; | ||
} | ||
else if (t === _Data) { | ||
const change = postTrace(_m); | ||
if (change.value !== value) { | ||
value = change.value; | ||
} | ||
broadcast(_Data, change, sinks); | ||
} | ||
else if (t === _End) { | ||
terminate(_m); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -49,0 +47,0 @@ }; |
{ | ||
"name": "callbag-state", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Callbag-based State Management", | ||
@@ -5,0 +5,0 @@ "main": "dist/es5/index.js", |
@@ -27,3 +27,3 @@ # callbag-state | ||
👉 Track the state via `.set()` and `.get()`: | ||
👉 Track the state and mutate it via `.set()` and `.get()`: | ||
```ts | ||
@@ -30,0 +30,0 @@ import state from 'callbag-state'; |
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
76171
850