ObservableObject: reflectValues()
プロパティの状態を更新します。
構文
observableObject.reflectValues(valueMap) => object
引数
-
valueMap:object更新するプロパティ名と値の組となるオブジェクトです。
返値: object
引数 valueMap の各プロパティに対して更新した結果の値を格納したオブジェクトです。
更新に成功したプロパティは更新結果の値となり、更新に失敗したプロパティは元の値となります。
例
ターゲットにプロパティ値を反映させない例です。
// 双方向を許可しない
const source = new ObservableObject({ output: "foo" }, false);
const target1 = Object.assign(Object.create(target_proto), { output: "" });
// 双方向を要求するが許可されていない
source.bindData(target1, true);
const target2 = Object.assign(Object.create(target_proto), { output: "" });
// 単方向を要求
source.bindData(target2, false);
// ターゲットは更新されない
target1.reflectValues({ output: "bar" });
// source.output => foo
// target1.output => foo
// target2.output => foo
// ターゲットは更新されない
target2.reflectValues({ output: "bar" });
// source.output => foo
// target1.output => foo
// target2.output => foo
// ターゲットが更新される
source.reflectValues({ output: "bar" });
// source.output => bar
// target1.output => bar
// target2.output => bar
解説
引数 valueMap のプロパティの中で、バインディングソースの同期対象となっているプロパティが valueMap のプロパティ値に更新されます。
この関数の呼び出しによってバインディングターゲットが実装する reflectValues() が呼び出されます。