Skip to content

Specy/stack-context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stack context

A library to store data inside of the stack, so you can retrieve it anywhere in the call stack, only in sync code.

It was an experiment to replicate AsyncLocalStorage, which works, but only for sync code (could be made much simpler, just wanted to experiment with storing things in the stack)

import { StackContext } from "@specy/stack-context";

type MyState = {
  a: number;
  b: number;
};

function sum() {
  const state = StackContext.state<MyState>();
  const sum = state.a + state.b;
  console.log(`The sum is: `, sum);
}

StackContext.root(
  () => {
    sum();
  },
  { a: 10, b: 20 },
);

About

A library to store data anywhere in a call stack, only in sync code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published