Git Product home page Git Product logo

Comments (5)

JeremyRH avatar JeremyRH commented on May 3, 2024

This is great! It would be good to test the performance when React is not in development mode. I was seeing comparable speeds with the production version of React.

But this is definitely worth exploring. I was just prototyping something that involved updating the store without calling React's dispatch (not performance related). It seems like we should enable full features for reading and writing state outside of React. We might need to make some of the types less strict. I'll look into this today.

from zustand.

JeremyRH avatar JeremyRH commented on May 3, 2024

It's difficult to define the function signature of StateListener. Apparently generics are inferred as {} if used before being assigned a type. StateSelector is the second argument so the generic U is not inferred yet when the StateListener type is defined. I was able to get it to work by reversing the parameter order: subscribe(selector | listener, listener) but I don't like it.

from zustand.

drcmda avatar drcmda commented on May 3, 2024

you mean i could either do

sub(state => console.log("state changed"))

or

sub(state => state.x, x => console.log("x has changed"))

?

I would actually prefer this : D but probably only because i don't know TS good enough to see the downsides (?)

from zustand.

JeremyRH avatar JeremyRH commented on May 3, 2024

Yes, you would be able to do that. The selector function is optional and I'm used to optional parameters being last. Haha I guess it's mostly preference though. If you like it, I'm fine with it.

from zustand.

drcmda avatar drcmda commented on May 3, 2024

Wound you merge it? I think this functionality would make it very versatile.

from zustand.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.