UNPKG

unissist

Version:

A persistance library for unistore

3 lines (2 loc) 2.67 kB
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("react-native")):"function"==typeof define&&define.amd?define(["react-native"],n):t.unissist=n(t.reactNative)}(this,function(t){const n=function(){function t(){}return t.prototype.then=function(n,r){const o=new t,i=this.s;if(i){const t=1&i?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 i=t.v;1&t.s?e(o,1,n?n(i):i):r?e(o,1,r(i)):e(o,2,i)}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 i=t.o;i&&i(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 i(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(i):i(t)),this._pact=new n},t.prototype.next=function(t){const i=this;return i._promise=new Promise(function(u){const s=i._pact;if(null===s){const t=i._entry;if(null===t)return u(i._promise);function c(t){i._resolve(t&&t.then?t.then(o):o(t)),i._pact=null,i._resolve=null}i._entry=null,i._resolve=u,t(i).then(c,function(t){if(t===r)c(i._return);else{const e=new n;i._resolve(e),i._pact=null,i._resolve=null,_resolve(e,2,t)}})}else i._pact=null,i._resolve=u,e(s,1,t)})},t.prototype.return=function(t){const n=this;return n._promise=new Promise(function(i){const u=n._pact;if(null===u)return null===n._entry?i(n._promise):(n._entry=null,i(t&&t.then?t.then(o):o(t)));n._return=t,n._resolve=i,n._pact=null,e(u,2,r)})},t.prototype.throw=function(t){const n=this;return n._promise=new Promise(function(r,o){const i=n._pact;if(null===i)return null===n._entry?r(n._promise):(n._entry=null,o(t));n._resolve=r,n._pact=null,e(i,2,t)})}}();return 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.umd.js.map