bindings: the zen of montage

29
Bindings The Zen of Montage sch, @benoitmarchant, @montagejs

Upload: kris-kowal

Post on 01-Nov-2014

710 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Bindings: the zen of montage

BindingsThe Zen of Montage

@kriskowal (speaking), @mikeczepiel, @aadsm, @francoisfrisch, @benoitmarchant, @montagejs

Page 2: Bindings: the zen of montage

function Point(x, y) { this.x = x; this.y = y;}Point.prototype.magnitude = function () { return Math.sqrt( this.x * this.x + this.y * this.y );};

var point = new Point(3, 4);expect(point.magnitude()).toEqual(5);

Page 3: Bindings: the zen of montage

var Montage = require("montage").Montage;var Point = Montage.create(Montage, { didCreate: { value: function () { this.addOwnPropertyChangeListener("x", this, "coordinate"); this.addOwnPropertyChangeListener("y", this, "coordiante"); } }, handleCoordinateChange: { value: function () { if (this.x == null || this.y == null) { this.magnitude = null; } else { this.magnitude = Math.sqrt( this.x * this.x + this.y * this.y ); } } }});

var point = Point.create();point.x = 3;point.y = 4;expect(point.magnitude).toEqual(5);

Page 4: Bindings: the zen of montage

var Montage = require("montage").Montage;var Point = Montage.create(Montage, { didCreate: { value: function () { this.defineBinding("magnitude", { "<-": "(x ** 2 + y ** 2) // 2" }); } }});

var point = Point.create();point.x = 3;point.y = 4;expect(point.magnitude).toEqual(5)

Page 5: Bindings: the zen of montage
Page 6: Bindings: the zen of montage

Discrete Change Listeners

● property changes● range changes● map changes

Page 7: Bindings: the zen of montage

Property Changes

object.addOwnPropertyChangeListener

(key, handler, token)

handler.handleTokenChange

(value, key, object)

add/remove

propertyChange/beforePropertyChange

tokenChange/tokenWillChange

Page 8: Bindings: the zen of montage

Map Changes

object.addMapChangeListener

(handler, token) (any key)

handler.handleTokenMapChange

(value, key, object)

add/remove

mapChange/beforeMapChange

mapChange/mapWillChange

Page 9: Bindings: the zen of montage

Range Changes

object.addRangeChangeListener

(handler, token)

handler.handleTokenRangeChange

(plus, minus, index)

add/remove

rangeChange/beforeRangeChange

rangeChange/rangeWillChange

Page 10: Bindings: the zen of montage
Page 11: Bindings: the zen of montage

Array Range Changes

shift() → splice(0, 1)unshift(...values) → splice(0, 0, ...values)push(...values) → splice(length, 0, ...values)pop() → splice(length - 1, 1)clear() → splice(0, length)set(index, value) → splice(index, 1, value)swap(i, l, values) → splice(i, l, ...values)

Page 12: Bindings: the zen of montage

© Sidney Harris — http://www.sciencecartoonsplus.com/

Page 13: Bindings: the zen of montage

Bindings

a ↔ ba.b ↔ c.da ← b.map{c}a ← b.filter{c}a ← b.sorted{c}a ← b.flatten()sum, average,reversed, enumerate,items, some, every

a.has(b) ↔ ca == b ↔ ca[b] ↔ ca.* ← c.map{d}a[*] ← b.toMap()a ← b.toMap{[.0, .1]}r ← (x**2 + y**2) //2f ↔ c * 1.8 + 32a ← b.{x: .0, y: .1}

Page 14: Bindings: the zen of montage

http://montagejs.github.com/frb/grammar.xhtml

Pipelines

Page 15: Bindings: the zen of montage

http://montagejs.github.com/frb/grammar.xhtml

Page 16: Bindings: the zen of montage

Insert Demo Here

Page 17: Bindings: the zen of montage

a.b ↔ c.d

this.defineBinding("a.b", { "<->": "c.d"});

{ "prototype": "montage", "bindings": { "a.b": {"<->": "c.d"} }}

Page 18: Bindings: the zen of montage

"selectionName": {

"prototype": "montage/ui/dynamic-text.reel",

"properties": {

"element": {"#": "selectionName"}

},

"bindings": {

"value": {

"<-": "

@selection.currentIteration.object.name + (

[email protected] ?

', ' : ''

)

"

}

}

}

Page 19: Bindings: the zen of montage

// Repetition.Iteration

// didCreate:

this.defineBinding("isLast", {

"<-": "

visibleIndex ==

repetition.iterations.length - 1

"

});

Page 20: Bindings: the zen of montage

// ContentController.Iteration

// didCreate:

this.defineBinding("selected", {

"<->": "controller.selection.has(object)"

});

Page 21: Bindings: the zen of montage

Insert More Awesomer Demo Here

Page 22: Bindings: the zen of montage

"valueInput": {

"prototype": "montage/ui/input-text.reel",

"properties": {

"element": {"#": "valueInput"}

},

"bindings": {

"value": {

"<->": "

@owner.data

[[email protected]]

[[email protected]]

"

}

}

}

Page 23: Bindings: the zen of montage
Page 24: Bindings: the zen of montage

function observeProperty(object, key, emit, source, parameters) { var cancel = Function.noop; function propertyChange(value, key, object) { cancel(); cancel = emit(value, key, object) || Function.noop; } PropertyChanges.addOwnPropertyChangeListener( object, key, propertyChange ); propertyChange(object[key], key, object); return once(function cancelPropertyObserver() { cancel(); PropertyChanges.removeOwnPropertyChangeListener( object, key, propertyChange ); });}

Page 25: Bindings: the zen of montage

exports.makeSumObserver = makeCollectionObserverMaker(

function setup() {

var sum = 0;

return function rangeChange(plus, minus, index) {

sum += plus.sum() - minus.sum();

return sum;

};

}

);

Page 26: Bindings: the zen of montage

Upcoming Changes

● array.property → array.map

{property}

● array.count() →

array.length

Page 27: Bindings: the zen of montage

Upcoming Changes

this.defineBinding(target, targetPath, {

"<- or <->": boundObjectPropertyPath,

source: boundObject

});

Page 28: Bindings: the zen of montage

http://{github,documentup}.com/montagejs/frb

Page 29: Bindings: the zen of montage

http://{github,documentup}.com/montagejs/frb