DEV Community

Discussion on: Building a Reactive Library from Scratch

 
peerreynders profile image
peerreynders

I still can't make sense of the types.

Sometimes clarity comes from the chosen names.

Change #1:

// A Dependency has many different Subscribers depending on it
// A particular Subscriber has many Dependencies it depends on
type Dependency = Set<Subscriber>;
type Subscriber = {
  execute(): void;
  dependencies: Set<Dependency>;
};
Enter fullscreen mode Exit fullscreen mode

Change #2:

  const subscriptions: Dependency = new Set();
Enter fullscreen mode Exit fullscreen mode

Change #3:

function cleanup(running: Subscriber) {
Enter fullscreen mode Exit fullscreen mode

Change #4:

  const running: Subscriber = {
    execute,
    dependencies: new Set(),
  };
Enter fullscreen mode Exit fullscreen mode

TypeScipt Playground

Thread Thread
 
mindplay profile image
Rasmus Schultz
// A Dependency has many different Subscribers depending on it
// A particular Subscriber has many Dependencies it depends on
Enter fullscreen mode Exit fullscreen mode

Yes! This is what the article/video/example was missing. Thank you! 😀🙏