Skip to content

Montage ♥ FRB

mczepiel edited this page Mar 8, 2013 · 20 revisions

FAQ for the FRB Transition

How do I observe a path from my object for changes after they've happened?

Before

myObject.addPropertyChangeListener("path", handler)

When the path changes myObject.handleChange(notification) will be called

After

myMontageObject.addPathChangeListener("path", handler, opt_methodName)

or

Montage.addPathChangeListener.call(myObject, "path", handler, opt_methodName)

myMontageObject is an object that has Montage in its prototype chain: Montage.isPrototypeOf(myMontageObject) === true holds.

When the value at the path changes (not the content of the value), the first function in this list gets called with the newValue, path, and myObject.

  • handler[methodName]
  • handler.handlePathChange
  • handler

How do I observe a path from my object for changes before they happen?

Before

myObject.addPropertyChangeListener("path", handler, true)

After

myMontageObject.addPathChangeListener("path", handler, "handleMethodName", true)

or

Montage.addPathChangeListener.call(myObject, "path", handler, "handleMethodName", true)

How do I bind a property of my object to a property of another object such that they are always the same?

Before

Object.defineBinding(myObject, "myProperty", {
    boundObject: anotherObject,
    boundObjectPropertyPath: "foo.bar"
});

After

myMontageObject.defineBinding("myProperty", {"<->": "foo.bar", source: anotherObject});

or

var Bindings = require("montage/core/bindings").Bindings;
Bindings.defineBinding(myObject, "myProperty", {"<->": "foo.bar", source: anotherObject});

How do I bind a property of my object to a property of another object such that changes to myProperty do not affect the otherObject's property?

Before

Object.defineBinding(myObject, "myProperty", {
    boundObject: anotherObject,
    boundObjectPropertyPath: "foo.bar",
    oneway: true
});

After

myMontageObject.defineBinding("myProperty", {"<-": "foo.bar", source: anotherObject});

or

var Bindings = require("montage/core/bindings").Bindings;
Bindings.defineBinding(myObject, "myProperty", {"<-": "foo.bar", source: anotherObject});

How do I watch changes to an array at the end of a property path so I know what's added and removed?

myMontageObject.addRangeAtPathChangeListener("array", handler, "handleArrayRangeChange");

or

Montage.addRangeAtPathChangeListener(myObject, "array", handler, "handleArrayRangeChange");

Calls handler.handleArrayRangeChange with plus, minus, and index.

How do I change a private value and dispatch the change on an affected public property?

Before

myObject.dispatchPropertyChange("affectedProperty", function () {
    myObject._underlyingProperty = newValue;
});