Created
June 2, 2021 05:03
-
-
Save zapplebee/78653eede28f2d11b49011bceff4797f to your computer and use it in GitHub Desktop.
This file contains 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
function createCtx() { | |
const ctx = {}; | |
return { | |
useCtx: () => ctx["ctx"] ?? null, | |
defineCtx: (val, callback) => { | |
ctx["ctx"] = val; | |
return callback(); | |
}, | |
}; | |
} | |
const { defineCtx: defineMeatCtx, useCtx: useMeatCtx } = createCtx(); | |
const { defineCtx: defineShapeCtx, useCtx: useShapeCtx } = createCtx(); | |
function meat() { | |
const meat = useMeatCtx(); | |
const shape = useShapeCtx(); | |
return `1 all ${meat} ${shape}`; | |
} | |
function beefPatty() { | |
const r = defineMeatCtx("beef", () => defineShapeCtx("patty", () => meat())); | |
console.log(r); | |
} | |
beefPatty(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment