UNPKG

unissist

Version:

A persistance library for unistore

3 lines (2 loc) 2.48 kB
var t=require("react-native");const n=function(){function t(){}return t.prototype.then=function(n,r){const o=new t,u=this.s;if(u){const t=1&u?n:r;if(t){try{e(o,1,t(this.v))}catch(t){e(o,2,t)}return o}return this}return this.o=function(t){try{const u=t.v;1&t.s?e(o,1,n?n(u):u):r?e(o,1,r(u)):e(o,2,u)}catch(t){e(o,2,t)}},o},t}();function e(t,r,o){if(!t.s){if(o instanceof n){if(!o.s)return void(o.o=e.bind(null,t,r));1&r&&(r=o.s),o=o.v}if(o&&o.then)return void o.then(e.bind(null,t,r),e.bind(null,t,2));t.s=r,t.v=o;const u=t.o;u&&u(t)}}const r={};!function(){function t(t){this._entry=t,this._pact=null,this._resolve=null,this._return=null,this._promise=null}function o(t){return{value:t,done:!0}}function u(t){return{value:t,done:!1}}t.prototype[Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))]=function(){return this},t.prototype._yield=function(t){return this._resolve(t&&t.then?t.then(u):u(t)),this._pact=new n},t.prototype.next=function(t){const u=this;return u._promise=new Promise(function(i){const s=u._pact;if(null===s){const t=u._entry;if(null===t)return i(u._promise);function c(t){u._resolve(t&&t.then?t.then(o):o(t)),u._pact=null,u._resolve=null}u._entry=null,u._resolve=i,t(u).then(c,function(t){if(t===r)c(u._return);else{const e=new n;u._resolve(e),u._pact=null,u._resolve=null,_resolve(e,2,t)}})}else u._pact=null,u._resolve=i,e(s,1,t)})},t.prototype.return=function(t){const n=this;return n._promise=new Promise(function(u){const i=n._pact;if(null===i)return null===n._entry?u(n._promise):(n._entry=null,u(t&&t.then?t.then(o):o(t)));n._return=t,n._resolve=u,n._pact=null,e(i,2,r)})},t.prototype.throw=function(t){const n=this;return n._promise=new Promise(function(r,o){const u=n._pact;if(null===u)return null===n._entry?r(n._promise):(n._entry=null,o(t));n._resolve=r,n._pact=null,e(u,2,t)})}}();module.exports=function(n){return n=n||"unistorePersist",{getState:function(){try{function e(){return null!==r?r:void 0}var r,o=function(t,n){try{var e=t()}catch(t){return n(t)}return e&&e.then?e.then(void 0,n):e}(function(){var e=JSON,o=e.parse;return Promise.resolve(t.AsyncStorage.getItem(n)).then(function(t){r=o.call(e,t)})},function(){});return Promise.resolve(o&&o.then?o.then(e):e())}catch(t){return Promise.reject(t)}},setState:function(e){try{return t.AsyncStorage.setItem(n,JSON.stringify(e))}catch(t){}},clearState:function(){try{return t.AsyncStorage.removeItem(n)}catch(t){}}}}; //# sourceMappingURL=asyncStorageAdapter.js.map