Comments (3)
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.
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.
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)
- Assess whether dispatchBeforeOwnPropertyChange and co have ever been used in any real project HOT 3
- row.toArray is not a function while use where or orderBy function
- Missing Tree
- Deque is missing from collections.min.js
- Collections interrupt MongoDB connection
- Typo in the documentation for findGreatestLessThan()
- List findValue is not a function
- A question of collections usage to solve Typescript issue related to tuple key in hashmap HOT 1
- How to use collections in Angular? HOT 4
- Maximum Call stack size reached on Shim-Array HOT 14
- shim-array version of Array.from not compatible with object with length property HOT 4
- Add data structure Trie HOT 1
- [feature request] SortedMap pop and shift methods
- MultiMap doesn't seem to be functioning properly
- updating the contentCompare in SortedSet
- Set behavior vary from Browser vs Node? HOT 6
- Add browser support where eval is not allowed by CSP HOT 1
- fast-map breaks mercurius
- Bugs in negated `in` expressions
- Is collections.js dead?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collections.