• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript object-reference.Meta类代码示例发布时间:2022-05-28
下一篇:
TypeScript object.Mixin类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap