當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript object-reference.setProperty函數代碼示例

本文整理匯總了TypeScript中@glimmer/object-reference.setProperty函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript setProperty函數的具體用法?TypeScript setProperty怎麽用?TypeScript setProperty使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了setProperty函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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:asakusuma,項目名稱: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:jayphelps,項目名稱:glimmer,代碼行數:101,代碼來源:reference-test.ts

示例3: equalsElement

  @test "Inside a loop"() {
    this.testType = 'Dynamic';
    this.registerComponent("Basic", "FooBar", "<p>{{@value}}</p>");

    let roots = [
      { id: 0, element: document.createElement('div'), value: 'foo' },
      { id: 1, element: document.createElement('div'), value: 'bar' },
      { id: 2, element: document.createElement('div'), value: 'baz' },
    ];

    this.render(
      stripTight`
        {{~#each roots key="id" as |root|~}}
          {{~#in-element root.element ~}}
            {{component 'FooBar' value=root.value}}
          {{~/in-element~}}
        {{~/each}}
        `,
      {
        roots
      }
    );

    equalsElement(roots[0].element, 'div', {}, '<p>foo</p>');
    equalsElement(roots[1].element, 'div', {}, '<p>bar</p>');
    equalsElement(roots[2].element, 'div', {}, '<p>baz</p>');
    this.assertHTML("<!----><!----><!--->");
    this.assertStableRerender();

    set(roots[0], "value", "qux!");
    this.rerender();
    equalsElement(roots[0].element, 'div', {}, '<p>qux!</p>');
    equalsElement(roots[1].element, 'div', {}, '<p>bar</p>');
    equalsElement(roots[2].element, 'div', {}, '<p>baz</p>');
    this.assertHTML("<!----><!----><!--->");
    this.assertStableRerender();

    set(roots[1], "value", "derp");
    this.rerender();
    equalsElement(roots[0].element, 'div', {}, '<p>qux!</p>');
    equalsElement(roots[1].element, 'div', {}, '<p>derp</p>');
    equalsElement(roots[2].element, 'div', {}, '<p>baz</p>');
    this.assertHTML("<!----><!----><!--->");
    this.assertStableRerender();

    set(roots[0], "value", "foo");
    set(roots[1], "value", "bar");
    this.rerender();
    equalsElement(roots[0].element, 'div', {}, '<p>foo</p>');
    equalsElement(roots[1].element, 'div', {}, '<p>bar</p>');
    equalsElement(roots[2].element, 'div', {}, '<p>baz</p>');
    this.assertHTML("<!----><!----><!--->");
    this.assertStableRerender();
    this.testType = 'Basic';
  }
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:55,代碼來源:in-element.ts


注:本文中的@glimmer/object-reference.setProperty函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。