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 from "can-define/map/map";
import value from "can-value";
const outer = new DefineMap({
inner: {
key: "hello"
}
});
const keyObservable = value.to(outer, "inner.key");
keyObservable.value = "aloha";
// 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.