Giter Club home page Giter Club logo

Comments (4)

STRML avatar STRML commented on August 31, 2024

The only issue I can think of is change listeners - any ideas on this? Should we be checking for the presence of a change or change:${derivedKey} listener, then revert to the current behavior if present?

from ampersand-state.

latentflip avatar latentflip commented on August 31, 2024

The only issue I can think of is change listeners - any ideas on this? Should we be checking for the presence of a change or change:${derivedKey} listener, then revert to the current behavior if present?

Are there many situations where you would have a derived property on a model, but would have no change/change:${derivedKey} listeners on that model at all?

from ampersand-state.

latentflip avatar latentflip commented on August 31, 2024

I'm not going to suggest that this has as nice an API as a derived property does - I've not tried to abstract it in any way - but an alternative way of doing this if you don't need the change events, and just want a cached getter, is to just create a cached getter, using Object.defineProperty on the prototype, and something like lodash.memoize for the caching.

If you do need the change events, then I'm not sure that you can avoid the current behaviour.

Here's an example:

http://esnextb.in/?gist=acf4e2cae3bab5eae5f4

from ampersand-state.

STRML avatar STRML commented on August 31, 2024

Yes - I don't use change listeners at all, I'm using ampersand-state with a Flux pattern so I know exactly when changes have been made.

I often use derived properties to mask and cache expensive operations that are not used often - until now I had assumed that recalculation was only done at access, not if any dep had changed.

It should be relatively simple to record when change handlers have been attached. Can you think of any issues with this approach?

from ampersand-state.

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.