Comparing version 0.2.1 to 0.2.2
@@ -1,1 +0,1 @@ | ||
export declare function getState<S = any>(key: string): S | null; | ||
export declare function getState<S = any>(key: string): S; |
@@ -154,5 +154,6 @@ 'use strict'; | ||
var undefined_as_any = undefined; | ||
function getState(key) { | ||
var store = Storage.get(key); | ||
return store ? store.state : null; | ||
return store ? store.state : undefined_as_any; | ||
} | ||
@@ -163,3 +164,3 @@ | ||
if (store) { | ||
if (store && store.setState) { | ||
store.setState(key, value); | ||
@@ -166,0 +167,0 @@ } else { |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=require("react"),r=t(require("react-fast-compare")),n=require("immer"),o=t(require("mitt")),u=function(){function t(){}return t.set=function(e,r){var n=t.stores[e];n&&n.setState||(t.stores[e]=r)},t.get=function(e){return t.stores[e]},t}();u.stores={};var s=o(),i="STORE_INITED",a="STORE_UPDATED",f=function(){function t(t){var e=this;this.setters=[],this.setState=function(t,r){var n=e.getNextState(r);s.emit(a,{key:t,nextState:n}),e.state=n,e.setters.forEach((function(t){return t(n)}))},this.state=t}return t.prototype.getNextState=function(t){var e;if("function"!=typeof t)return t;if("object"!=typeof this.state)return t();var r=!0,o=n.produce(this.state,(function(n){var o=t(n);o&&"object"==typeof o&&(e=o,r=!1)}));return r&&(e=o),e},t}();function c(t,e,n){return function(o,a){var c=u.get(o),p=n(c?c.state:a).current;r(p,a),u.set(o,new f(p));var S=u.get(o),v=t(p),x=v[0],g=v[1],h=S.setters;return e((function(){return h.push(g),function(t){s.emit(i,t)}(o),function(){h.splice(h.indexOf(g),1)}}),[]),[x,function(t){return function(e){return S.setState(t,e)}}(o)]}}var p=c(e.useState,e.useEffect,e.useRef);exports.Storage=u,exports.createUseStore=c,exports.getState=function(t){var e=u.get(t);return e?e.state:null},exports.mutate=function(t,e){var r=u.get(t);r?r.setState(t,e):u.set(t,{state:e})},exports.onStoreInit=function(t){s.on(i,(function(e){t(e)}))},exports.onStoreUpdate=function(t){s.on(a,(function(e){t(e)}))},exports.useStore=p; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=require("react"),r=t(require("react-fast-compare")),n=require("immer"),o=t(require("mitt")),u=function(){function t(){}return t.set=function(e,r){var n=t.stores[e];n&&n.setState||(t.stores[e]=r)},t.get=function(e){return t.stores[e]},t}();u.stores={};var s=o(),i="STORE_INITED",a="STORE_UPDATED",f=function(){function t(t){var e=this;this.setters=[],this.setState=function(t,r){var n=e.getNextState(r);s.emit(a,{key:t,nextState:n}),e.state=n,e.setters.forEach((function(t){return t(n)}))},this.state=t}return t.prototype.getNextState=function(t){var e;if("function"!=typeof t)return t;if("object"!=typeof this.state)return t();var r=!0,o=n.produce(this.state,(function(n){var o=t(n);o&&"object"==typeof o&&(e=o,r=!1)}));return r&&(e=o),e},t}();function c(t,e,n){return function(o,a){var c=u.get(o),p=n(c?c.state:a).current;r(p,a),u.set(o,new f(p));var S=u.get(o),v=t(p),x=v[0],g=v[1],h=S.setters;return e((function(){return h.push(g),function(t){s.emit(i,t)}(o),function(){h.splice(h.indexOf(g),1)}}),[]),[x,function(t){return function(e){return S.setState(t,e)}}(o)]}}var p=c(e.useState,e.useEffect,e.useRef);exports.Storage=u,exports.createUseStore=c,exports.getState=function(t){var e=u.get(t);return e?e.state:void 0},exports.mutate=function(t,e){var r=u.get(t);r&&r.setState?r.setState(t,e):u.set(t,{state:e})},exports.onStoreInit=function(t){s.on(i,(function(e){t(e)}))},exports.onStoreUpdate=function(t){s.on(a,(function(e){t(e)}))},exports.useStore=p; | ||
//# sourceMappingURL=stook.cjs.production.min.js.map |
@@ -150,5 +150,6 @@ import { useRef, useEffect, useState } from 'react'; | ||
var undefined_as_any = undefined; | ||
function getState(key) { | ||
var store = Storage.get(key); | ||
return store ? store.state : null; | ||
return store ? store.state : undefined_as_any; | ||
} | ||
@@ -159,3 +160,3 @@ | ||
if (store) { | ||
if (store && store.setState) { | ||
store.setState(key, value); | ||
@@ -162,0 +163,0 @@ } else { |
{ | ||
"name": "stook", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"license": "MIT", | ||
@@ -50,3 +50,4 @@ "author": "forsigner", | ||
"react-fast-compare": "^2.0.4" | ||
} | ||
}, | ||
"gitHead": "ec6094edfe15eac6c3d9d713f658ae3dc7c2955a" | ||
} |
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
36857
19
343