Create a gist now

Instantly share code, notes, and snippets.

Embed
watch the changes of some object or attribute
@melanke

This comment has been minimized.

Show comment
Hide comment
@melanke

melanke Jan 23, 2012

It is really usefull!

Owner

melanke commented Jan 23, 2012

It is really usefull!

@mahanmp

This comment has been minimized.

Show comment
Hide comment
@mahanmp

mahanmp Apr 20, 2012

seems to have some conflicts with jquery... I used a lot of jquery functions and seems it become undefined when i just include this script on my pages

mahanmp commented Apr 20, 2012

seems to have some conflicts with jquery... I used a lot of jquery functions and seems it become undefined when i just include this script on my pages

@melanke

This comment has been minimized.

Show comment
Hide comment
@melanke

melanke Apr 20, 2012

Thank you very much! I've updated the gist! I think now you are able to use JQuery properly! =)

Owner

melanke commented Apr 20, 2012

Thank you very much! I've updated the gist! I think now you are able to use JQuery properly! =)

@melanke

This comment has been minimized.

Show comment
Hide comment
@melanke

melanke Apr 23, 2012

the method attributes() was removed, it is not necessary anymore

Owner

melanke commented Apr 23, 2012

the method attributes() was removed, it is not necessary anymore

@MikeAski

This comment has been minimized.

Show comment
Hide comment
@MikeAski

MikeAski Jul 20, 2012

Otherwise, you've got EmberJS for those kind of stuff...

Otherwise, you've got EmberJS for those kind of stuff...

@melanke

This comment has been minimized.

Show comment
Hide comment
@melanke

melanke Jul 20, 2012

EmberJS is pretty much similar to BackboneJS, isn't it?

The purpose of WatchJS is to give freedom to the developer.

"with Watch.JS you will not have to change your way to develop"

WatchJS use your objects, anyway you want to build them.

EmberJS force you to use his constructor. I dont like it

Owner

melanke commented Jul 20, 2012

EmberJS is pretty much similar to BackboneJS, isn't it?

The purpose of WatchJS is to give freedom to the developer.

"with Watch.JS you will not have to change your way to develop"

WatchJS use your objects, anyway you want to build them.

EmberJS force you to use his constructor. I dont like it

@penartur

This comment has been minimized.

Show comment
Hide comment
@penartur

penartur Aug 16, 2012

It is not that obvious from the readme that watchAll only watches for properties that were defined at the moment of call to watchAll.

E.g.

var obj = {
    attr1: 0,
};

ex3.watch(function(){
    alert("Something was changed");
});

ex3.attr0 = 1; //triggers the observer; the alert is shown.
ex3.attr1 = 1; //does not trigger the observer; the alert is not shown.

It is not that obvious from the readme that watchAll only watches for properties that were defined at the moment of call to watchAll.

E.g.

var obj = {
    attr1: 0,
};

ex3.watch(function(){
    alert("Something was changed");
});

ex3.attr0 = 1; //triggers the observer; the alert is shown.
ex3.attr1 = 1; //does not trigger the observer; the alert is not shown.
@melanke

This comment has been minimized.

Show comment
Hide comment
@melanke

melanke Oct 18, 2012

@penartur it is explained in the paragraph "Chill out, no surprises, new attributes will not be considered"

Owner

melanke commented Oct 18, 2012

@penartur it is explained in the paragraph "Chill out, no surprises, new attributes will not be considered"

@hellodaylight

This comment has been minimized.

Show comment
Hide comment
@hellodaylight

hellodaylight Nov 9, 2012

This is really useful. Thanks. One question: when watching more than one properties, is there a way to see what and how it was changed? i.e.:

o.watch(["x","y","z"], function (id, oldval, newval) {
console.log( "o." + id + " changed from " + oldval + " to " + newval );
});

This is really useful. Thanks. One question: when watching more than one properties, is there a way to see what and how it was changed? i.e.:

o.watch(["x","y","z"], function (id, oldval, newval) {
console.log( "o." + id + " changed from " + oldval + " to " + newval );
});

@melanke

This comment has been minimized.

Show comment
Hide comment
@melanke

melanke Nov 10, 2012

With the new version of Watch.JS it is possible

Here is a sample:
http://jsfiddle.net/XnbXS/1/

Read the short-full-documentation:
https://github.com/melanke/Watch.JS

Owner

melanke commented Nov 10, 2012

With the new version of Watch.JS it is possible

Here is a sample:
http://jsfiddle.net/XnbXS/1/

Read the short-full-documentation:
https://github.com/melanke/Watch.JS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment