Code Monkey home page Code Monkey logo

Comments (3)

aadsm avatar aadsm commented on May 28, 2024

It is mention in the documentation under Map Changes: http://documentup.com/montagejs/collections#change-listeners/map-changes

The listener may be a delegate object with one of the following methods, in order of precedence:

listener.handleMap + Change or WillChange
listener.handle + token + Map + Change or WillChange
listener.call

Example:
The token can be useful when you're listening to map changes of different objects.

var delegate = {
    handleArticlesMapChange: function(value, key, object) {

    },
    handleMoviesMapChange: function(value, key, object) {

    }
};

articles.addMapChangeListener(delegate, "Articles");
movies.addMapChangeListener(delegate, "Movies");

The before is a flag that when set to true will make the listener to be called just before the change instead of after the change. When this is the case the delegate method name to be called is in the handle*MapWillChange format.

from collections.

thanpolas avatar thanpolas commented on May 28, 2024

ok got it, thanks @aadsm

It is a bit complicated, no?

One would expect on(fn, 'token'); to listen for changes on the token prop and have fn triggered...

from collections.

Stuk avatar Stuk commented on May 28, 2024

The Maps are different, in that they have properties (length, store) and content. So that there is no confusion about whether you want to listen to a property change (addOwnPropertyChangeListener) or a change in the content there are different methods. Maps also have the advantage over normal objects in that we know when any key/value changes, and so the API exposes that power.

If you want to listen to just one key/value change in a Map you can use an if inside the listener. If you want to listen to a property on the actual object (or any Javascript object) then you need to use addOwnPropertyChangeListener.

I agree it is confusing at first, but they do do different tasks that can't be combined without introducing ambiguity.

from collections.

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.