noNotify argument of MVCObject

75 views
Skip to first unread message

Masashi.K

unread,
Oct 6, 2011, 5:59:00 PM10/6/11
to google-map...@googlegroups.com
Hi all -

I wonder does "noNotify" argument of MVCObject.bindTo() method works correctly?

The maps api v3 reference said:
(http://goo.gl/LkcPh)
------------------
>bindTo(key:string, target:MVCObject, targetKey?:string, noNotify?:boolean)
Binds a View to a Model.

>notify(key:string)
Notify all observers of a change on this property.
This notifies both objects that are bound to the object's property as
well as the object that it is bound to.
------------------

And a previous post about MVCObject said:
(http://goo.gl/uR0l2)
------------------
>We do - calling
> model.notify("enabled")
>is equivalent to calling
> google.maps.event.trigger(model, "enabled_changed")
>ie. MVCObject uses events for notification.
------------------


So I recognize if I set the value "true" to noNotify argument
the MVCObject would not fire the "(key)_changed" event, but it works.
<test code>
--------------------
var mvcObject1 = new google.maps.MVCObject();
mvcObject1.set("visible", true);

var mvcObject2 = new google.maps.MVCObject();
mvcObject2.bindTo("visible", mvcObject1, "visible", true); //noNotify = true

google.maps.event.addListener(mvcObject2, "visible_changed", function(){
// I believe this alert never display
alert("visible_changed");
});

var chkbox = document.getElementById("chkbox");
google.maps.event.addDomListener(chkbox, "click", function(){
mvcObject1.set("visible", chkbox.checked);
});
--------------------

Do I have wrong understand, or bug?
Please tell me.

- Masashi

Enoch Lau (Google Employee)

unread,
Oct 6, 2011, 6:26:03 PM10/6/11
to google-map...@googlegroups.com
The noNotify argument is to specify that you don't want to be notified on bind, not that you don't ever want to be notified.

Enoch

Masashi.K

unread,
Oct 6, 2011, 7:03:13 PM10/6/11
to Google Maps JavaScript API v3
I see.
I've understand the meaning, but I can not understand how to use it.
Could you tell me any snippet?

(I like MVCObject class because it's useful)

On 10月6日, 午後3:26, "Enoch Lau (Google Employee)" <enoch...@google.com>
wrote:
> The noNotify argument is to specify that you don't want to be notified on *
> bind*, not that you don't ever want to be notified.
>
> Enoch

Masashi.K

unread,
Oct 6, 2011, 8:07:48 PM10/6/11
to Google Maps JavaScript API v3
Ok, I finally understand.
-------------------------------------
var mvcObject1 = new google.maps.MVCObject();
mvcObject1.set("visible", true);

var mvcObject2 = new google.maps.MVCObject();
mvcObject2.visible_changed = function(){
alert("visible_changed");
};
mvcObject2.bindTo("visible", mvcObject1, "visible", false); //
noNotify = false
//mvcObject2.bindTo("visible", mvcObject1, "visible", true); //
noNotify = true
-------------------------------------

Masashi.K

unread,
Oct 6, 2011, 8:14:35 PM10/6/11
to Google Maps JavaScript API v3
Oops, I forgot. Thank you, Enoch.

Enoch Lau (Google Employee)

unread,
Oct 6, 2011, 8:18:02 PM10/6/11
to google-map...@googlegroups.com
That's right. When you install the event listener before the bindTo, ordinarily, the event listener will be triggered at the time you do the bindTo. To avoid that, you can specify noNotify, which causes the event listener to be not triggered when you call bindTo.

Enoch

Masashi.K

unread,
Oct 6, 2011, 8:48:58 PM10/6/11
to Google Maps JavaScript API v3
I see, that makes sense.
I'm happy for fully understanding.
Thanks again!

On 10月6日, 午後5:18, "Enoch Lau (Google Employee)" <enoch...@google.com>
wrote:
Reply all
Reply to author
Forward
0 new messages