本文整理汇总了TypeScript中glimmer-object-reference.setProperty函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setProperty函数的具体用法?TypeScript setProperty怎么用?TypeScript setProperty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setProperty函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: set
export function set(obj, key, value) {
if (key.indexOf('.') !== -1) {
let path = key.split('.');
let parent = path.slice(0, -1).reduce((obj, key) => obj[key], obj);
setProperty(parent, path[path.length - 1], value);
} else {
setProperty(obj, key, value);
}
}
示例2: function
QUnit.test("basic reference data flow", function() {
let obj1 = { label: "obj1", model: { person: { name: { first: "Yehuda", last: "Katz" } } } };
let obj2 = { label: "obj2", model: { person: { name: obj1.model.person.name } } };
let obj3 = { label: "obj3", model: { person: obj1.model.person } };
let obj4 = { label: "obj4", model: obj1.model };
let originalPerson = obj1.model.person;
let o1 = [
addObserver(obj1, 'obj1', 'model.person.name.first'),
addObserver(obj1.model, 'obj1.model', 'person.name.first'),
addObserver(obj1.model.person, 'obj1.model.person', 'name.first'),
addObserver(obj1.model.person.name, 'obj1.model.person.name', 'first')
];
let o2 = [
addObserver(obj2, 'obj2', 'model.person.name.first'),
addObserver(obj2.model, 'obj2.model', 'person.name.first'),
addObserver(obj2.model.person, 'obj2.model.person', 'name.first'),
addObserver(obj2.model.person.name, 'obj2.model.person.name', 'first')
];
let o3 = [
addObserver(obj3, 'obj3', 'model.person.name.first'),
addObserver(obj3.model, 'obj3.model', 'person.name.first'),
addObserver(obj3.model.person, 'obj3.model.person', 'name.first'),
addObserver(obj3.model.person.name, 'obj3.model.person.name', 'first')
];
let o4 = [
addObserver(obj4, 'obj4', 'model.person.name.first'),
addObserver(obj4.model, 'obj4.model', 'person.name.first'),
addObserver(obj4.model.person, 'obj4.model.person', 'name.first'),
addObserver(obj4.model.person.name, 'obj4.model.person.name', 'first')
];
allDirty(o1, "Yehuda");
allDirty(o2, "Yehuda");
allDirty(o3, "Yehuda");
allDirty(o4, "Yehuda");
allClean(o1);
allClean(o2);
allClean(o3);
allClean(o4);
setProperty(obj1.model, 'person', { name: { first: 'Godfrey', last: 'Chan' } });
isDirty(o1[0], "Godfrey");
isDirty(o1[1], "Godfrey");
isClean(o1[2]);
isClean(o1[3]);
allClean(o2);
allClean(o3);
isDirty(o4[0], "Godfrey");
isDirty(o4[1], "Godfrey");
isClean(o4[2]);
isClean(o4[3]);
setProperty(originalPerson.name, 'first', "Godhuda");
isClean(o1[0]);
isClean(o1[1]);
isDirty(o1[2], "Godhuda");
isDirty(o1[3], "Godhuda");
allDirty(o2, "Godhuda");
allDirty(o3, "Godhuda");
isClean(o4[0]);
isClean(o4[1]);
isDirty(o4[2], "Godhuda");
isDirty(o4[3], "Godhuda");
setProperty(obj1.model, 'person', undefined);
isDirty(o1[0], undefined);
isDirty(o1[1], undefined);
isClean(o1[2]);
isClean(o1[3]);
allClean(o2);
allClean(o3);
isDirty(o4[0], undefined);
isDirty(o4[1], undefined);
isClean(o4[2]);
isClean(o4[3]);
setProperty(obj1.model, 'person', originalPerson);
isDirty(o1[0], "Godhuda");
isDirty(o1[1], "Godhuda");
isClean(o1[2]);
isClean(o1[3]);
allClean(o2);
allClean(o3);
//.........这里部分代码省略.........