Skip to content
guankaishe edited this page Jan 23, 2015 · 5 revisions

Deep obsreve Object:

Use "deep" option, will observe prop of the instance recursively.

var mux = new Mux({
    deep: true,
    person: {
        info: {name:"switer", email: "guankaishe@gmail.com"}
    }
})

So it can set value to sub-property object by "=" operator directly:

mux.$watch('person.info.name', function (next, pre) {
    next // --> guankaishe
})
mux.person.info.name = 'guankaishe'

Deep observe Array:

Property's value type of Array also can be observed:

var mux = new Mux({
    deep: true,
    items: [{type: ""}, 1,2,3]
})

Modify sub-property which value is type of 'Object'

mux.$watch('items[0].type', function (next) {
    next // --> "array"
})
mux.items[0].type = 'array'

Self modify methods:

mux.$watch('items', function (next, pre) {
    next.length // --> 5
    pre.length // --> 4
})
mux.items.push(4)

Indecies:

mux.$watch('items[0]', function (next, pre) {
    next// --> 0
    pre// --> {type: "array"}
})
mux.items[0] = 0