Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derived Stores #40

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Derived Stores #40

wants to merge 21 commits into from

Conversation

crutchcorn
Copy link
Member

@crutchcorn crutchcorn commented Feb 7, 2024

This PR implements an initial Derived class implementation:

const count = new Store(10);

const doubleCount = new Derived([count], () => {
  return count.state * 2;
})

doubleCount.subscribe(() => console.log(doubleCount.state));
count.setState(() => 20);

This Derived implementation even solves the diamond problem:

"a" is the root node with "b" and "c" relying on it. Then "d" relies on both "b" and "c"

Where writes to "a" will call "d" twice (with a flicker of incorrect data known as a "Glitch") because of the dual-derived nature. Our implementation does not have this problem and therefore can be considered "glitch-free"

This is a push-based/hot signals implementation

Benchmarks

Due to the relatively naive nature of this code (I wrote it in one night at ~midnight) there are performance implication in using this. Namely, in our benchmarks we are a far cry from Angular or Solid's implementation, but come close to Vue's implementation:

@crutchcorn
Copy link
Member Author

image

I've increased our performance and reduced our bundle size. We're no-longer the slowest on our own benchmark and are even 1.5x faster than Vue:

image

@tannerlinsley
Copy link
Contributor

Woo! 🏎️

@eneajaho
Copy link

Angular is the fastest, nice 😄!

Copy link

nx-cloud bot commented Feb 17, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit de55814. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants