Example #1
0
File: tests.ts Project: benjamn/wry
  it("works with @wry/context", function () {
    const nameSlot = new Slot<string>();
    function withName<T = any>(name: string, exec: (task: Task<T>) => void) {
      return new Task<T>(task => nameSlot.withValue(name, () => exec(task)));
    }

    return withName("parent", task => {
      assert.strictEqual(nameSlot.getValue(), "parent");
      task.resolve(123);
    }).then(oneTwoThree => withName("child", child => {
      assert.strictEqual(nameSlot.getValue(), "child");

      const sibling = withName("sibling", task => {
        task.resolve(nameSlot.getValue());
      }).then(result => {
        assert.strictEqual(result, "sibling");
        assert.strictEqual(nameSlot.getValue(), "child");
      });

      setTimeout(() => {
        assert.strictEqual(nameSlot.getValue(), "child");
        child.resolve(withName("grandchild", grandchild => {
          assert.strictEqual(nameSlot.getValue(), "grandchild");
          sibling.then(() => {
            assert.strictEqual(nameSlot.getValue(), "grandchild");
            grandchild.resolve(oneTwoThree);
          }, grandchild.reject);
        }));
      }, 10);

    })).then(result => {
      assert.strictEqual(nameSlot.hasValue(), false);
      assert.strictEqual(result, 123);
    });
  });
Example #2
0
File: tests.ts Project: benjamn/wry
 child.resolve(withName("grandchild", grandchild => {
   assert.strictEqual(nameSlot.getValue(), "grandchild");
   sibling.then(() => {
     assert.strictEqual(nameSlot.getValue(), "grandchild");
     grandchild.resolve(oneTwoThree);
   }, grandchild.reject);
 }));
Example #3
0
File: tests.ts Project: benjamn/wry
    }).then(oneTwoThree => withName("child", child => {
      assert.strictEqual(nameSlot.getValue(), "child");

      const sibling = withName("sibling", task => {
        task.resolve(nameSlot.getValue());
      }).then(result => {
        assert.strictEqual(result, "sibling");
        assert.strictEqual(nameSlot.getValue(), "child");
      });

      setTimeout(() => {
        assert.strictEqual(nameSlot.getValue(), "child");
        child.resolve(withName("grandchild", grandchild => {
          assert.strictEqual(nameSlot.getValue(), "grandchild");
          sibling.then(() => {
            assert.strictEqual(nameSlot.getValue(), "grandchild");
            grandchild.resolve(oneTwoThree);
          }, grandchild.reject);
        }));
      }, 10);

    })).then(result => {
Example #4
0
File: tests.ts Project: benjamn/wry
 })).then(result => {
   assert.strictEqual(nameSlot.hasValue(), false);
   assert.strictEqual(result, 123);
 });
Example #5
0
File: tests.ts Project: benjamn/wry
 }).then(result => {
   assert.strictEqual(result, "sibling");
   assert.strictEqual(nameSlot.getValue(), "child");
 });
Example #6
0
File: tests.ts Project: benjamn/wry
 const sibling = withName("sibling", task => {
   task.resolve(nameSlot.getValue());
 }).then(result => {
Example #7
0
File: tests.ts Project: benjamn/wry
 return withName("parent", task => {
   assert.strictEqual(nameSlot.getValue(), "parent");
   task.resolve(123);
 }).then(oneTwoThree => withName("child", child => {
Example #8
0
File: tests.ts Project: benjamn/wry
 return new Task<T>(task => nameSlot.withValue(name, () => exec(task)));