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