Coder Social home page Coder Social logo

Filter on updates not working about reswift HOT 3 OPEN

sarensw avatar sarensw commented on June 4, 2024
Filter on updates not working

from reswift.

Comments (3)

DivineDominion avatar DivineDominion commented on June 4, 2024

@sarensw This is actually normal behavior (because even when you change a "leaf" in the state, the root value also changes). ReSwift offers to skip identical state updates when the states conform to Equatable. See: http://reswift.github.io/ReSwift/master/getting-started-guide.html#example-of-skipping-identical-state-updates

from reswift.

sarensw avatar sarensw commented on June 4, 2024

@DivineDominion , thanks a lot for the quickly reply. Interesting. I tried with .skip(==) and it works. Coming from Typescript + Redux, this seems strange, though.

I took the following selector from some of my TypeScript code.

// only if the reference of .current changes, then update the component
const currentFile = useAppSelector(state => state.files.current)

// only if the length of the .files array changes, then update the component
const count = useAppSelector(state => state.files.files?.length)

So I can be very specific about the updates that I want to be notified about. And I don't have to skip same values (let alone make sure that Equatable is implemented.

No complains here. Just something that I have to learn.

One thing that I also noticed is that I can't just select any arbitrary property that I want. It feels like it has to be struct what I can filter on. But maybe I am also missing something here.

from reswift.

DivineDominion avatar DivineDominion commented on June 4, 2024

@sarensw Swift is a bit stricter than vanilla JS when it comes to checking for value equality. It may be a good practice to slap "Equatable" onto all your subtypes just so you don't need to worry.

You can select arbitrary substates, but then you need to make them a Swift tuple. These suffer from not being equatable, so you get convenient substate selection but need to (!) add the .skip(==) manually. That's because for tuples between 2 and 6 elements, a == overload exists; but the tuple is not a type that ca conform to Equatable, so ReSwift can't skip it by default. See https://developer.apple.com/documentation/swift/equatable

Having said that:

We could copy the tuple == overload approach and offer substate selector overloads that do this by default, I believe. Requires tests, of course. If you'd be into that, let me know :)

from reswift.

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.