当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript glimmer-object-reference.setProperty函数代码示例

本文整理汇总了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);
  }
}
开发者ID:GCheung55,项目名称:glimmer,代码行数:9,代码来源:support.ts

示例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);
//.........这里部分代码省略.........
开发者ID:Radascript,项目名称:glimmer,代码行数:101,代码来源:reference-test.ts


注:本文中的glimmer-object-reference.setProperty函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。