Created
October 29, 2019 19:14
-
-
Save emartini/6f9816fe3907d34683f77fb39eb42723 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
se9i: function(t, e, n) { | |
"use strict"; | |
n.d(e, "a", function() { | |
return a; | |
}); | |
var r = n("q1tI"); | |
const o = (t, e) => ((t => "function" == typeof t)(e) ? e(t) : e), | |
i = t => { | |
const e = Object.keys(t); | |
let n = t; | |
const i = [], | |
a = Object(r.createContext)(t, (t, n) => { | |
let r = 0; | |
return ( | |
e.forEach((e, o) => { | |
t[e] !== n[e] && (r |= 1 << o); | |
}), | |
r | |
); | |
}), | |
c = (t, e) => { | |
(n = { ...n, [t]: o(n[t], e) }), i.forEach(t => t(n)); | |
}; | |
return { | |
GlobalStateProvider: ({ children: e }) => { | |
const [o, c] = Object(r.useState)(t); | |
return ( | |
Object(r.useEffect)( | |
() => ( | |
i.push(c), | |
n !== t && c(n), | |
() => { | |
const t = i.indexOf(c); | |
i.splice(t, 1); | |
} | |
), | |
[] | |
), | |
Object(r.createElement)(a.Provider, { value: o }, e) | |
); | |
}, | |
setGlobalState: c, | |
useGlobalState: t => { | |
const n = e.indexOf(t), | |
o = ((t, e) => { | |
const { | |
ReactCurrentDispatcher: n | |
} = r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, | |
o = n.current; | |
if (!o) | |
throw new Error( | |
"Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)" | |
); | |
return o.useContext(t, e); | |
})(a, 1 << n), | |
i = Object(r.useCallback)(e => c(t, e), [t]); | |
return [o[t], i]; | |
}, | |
getState: () => n, | |
setState: t => { | |
(n = t), i.forEach(t => t(n)); | |
} | |
}; | |
}, | |
a = (t, e, n) => { | |
if (n) return n(a)(t, e); | |
const { | |
GlobalStateProvider: r, | |
useGlobalState: o, | |
getState: c, | |
setState: u | |
} = i(e); | |
return { | |
GlobalStateProvider: r, | |
useGlobalState: o, | |
getState: c, | |
setState: u, | |
dispatch: e => { | |
const n = c(), | |
r = t(n, e); | |
return u(r), e; | |
} | |
}; | |
}; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment