Skip to content

Instantly share code, notes, and snippets.

@zapplebee
Created June 2, 2021 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapplebee/78653eede28f2d11b49011bceff4797f to your computer and use it in GitHub Desktop.
Save zapplebee/78653eede28f2d11b49011bceff4797f to your computer and use it in GitHub Desktop.
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