Giter Club home page Giter Club logo

Comments (5)

JiriZidek avatar JiriZidek commented on August 17, 2024 1

Maybe TS is smart enough to infer notnullability from this:
if(state.foo) state = iassign(state, g=>g.foo.bar, s => 1);
Otherwise ! might be used (or there is another syntax?).
if(state.foo) state = iassign(state, g=>g!.foo.bar, s => 1);

from immutableassign.

JiriZidek avatar JiriZidek commented on August 17, 2024

IMHO I think that your "if" logic should go to "setter" function. Getter is just "semantical description of path", it is not real imperative code... hence no imperative "if".

from immutableassign.

esamattis avatar esamattis commented on August 17, 2024

Hmm. That makes the setter bit awkward depending on the case. I think #15 would solve this nicely?

from immutableassign.

shroo-paulli avatar shroo-paulli commented on August 17, 2024

Interesting use case, I don't think #15 (proxy) would work for your case. But feel free to try out that pull request, and let me know if it works.

Another solution I can think of is using nested iassign.

const newState = i(
    state,
    s => s.foo,
    (foo) => {
        return i(foo || {}, (f) => f.bar, () => 1);
    },
);

from immutableassign.

engineforce avatar engineforce commented on August 17, 2024

Hi epeli,

Your use case should work now with 2.0.4 and following modification:

let newState = i(
    state,
    s => {
        const foo = s.foo;
        if (foo) {
            return foo.bar;
        }

        // must return the same value as the setProp() to prevent update.
        return 1;
    },
    () => 1,
    undefined,
    {
        ignoreIfNoChange: true,
    }
);

from immutableassign.

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.