to
Get an observable for setting (but not getting) a property on an object.
value.to( object, keyPath )
In the example below, a keyObservable
is created that is one-way bound to the
value at outer.inner.key
. When keyObservable.value
changes,
outer.inner.key
is updated, but changes to outer.inner.key
do not update
keyObservable.value
.
import {DefineMap, value} from "can";
const outer = new DefineMap({
inner: {
key: "hello"
}
});
const keyObservable = value.to(outer, "inner.key");
keyObservable.value = "aloha";
console.log( outer.inner.key ) //-> "aloha"
Parameters
- object
{Object}
:The object from which to read.
- keyPath
{String}
:A String of dot-separated keys, representing a path of properties.