Skip to content

Commit

Permalink
feat: the from method removed from signal.trigger and flag
Browse files Browse the repository at this point in the history
  • Loading branch information
betula committed Jun 22, 2021
1 parent c161aca commit c14a0c1
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 132 deletions.
14 changes: 0 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,18 +802,6 @@ const signal_trigger_flag = (initial) => make_trigger(!!initial, 1, 1);
const signal_trigger_flag_resolved = (val) => {
const flag = signal_trigger_flag(!val); flag(); return flag;
}
const signal_trigger_flag_from = (get) => {
const flag = signal_trigger_flag(untrack(get[key_get] || get));
reactionable_subscribe(get, flag);
obj_def_prop_value(flag, key_reset, () => trait_ent_reinit(flag, !!untrack(get[key_get] || get)));
return flag;
}
const signal_trigger_from = (get) => {
const ent = signal_trigger(untrack(get[key_get] || get));
reactionable_subscribe(get, ent);
obj_def_prop_value(ent, key_reset, () => trait_ent_reinit(ent, untrack(get[key_get] || get)))
return ent;
}
const signal_from = (get, set?) => {
const h = [get[key_get] || get];
h[key_is_signal] = 1
Expand All @@ -824,10 +812,8 @@ const signal_from = (get, set?) => {
}

signal_trigger_flag[key_resolved] = signal_trigger_flag_resolved;
signal_trigger_flag[key_from] = signal_trigger_flag_from;
signal_trigger[key_flag] = signal_trigger_flag;
signal_trigger[key_resolved] = signal_trigger_resolved;
signal_trigger[key_from] = signal_trigger_from;
signal[key_trigger] = signal_trigger as any;
signal[key_from] = signal_from;

Expand Down
6 changes: 0 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,18 +485,12 @@ type SignalEntry = {
resolved: {
(value: boolean): Signal<void, boolean>;
}
from: {
(get: Re<boolean>): SignalReadonly<boolean> & E_ResetPartial
}
}

resolved: {
<T>(value: T): Signal<void, T>;
(): Signal;
}
from: {
<O>(get: Re<O>): SignalReadonly<O> & E_ResetPartial
}
};

from: {
Expand Down
112 changes: 0 additions & 112 deletions tests/builder-5/trigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,118 +97,6 @@ test('should work signal.trigger wrapped', async () => {
expect(spy).toHaveBeenNthCalledWith(3, 20, 0);
});

test('should work signal.trigger from value', async () => {
const spy = jest.fn();

const s = value(1);
const r = signal.trigger.from(s);

sync(r, spy);

s(1);
s(2);
s(3);

expect(spy).toBeCalledTimes(2);
expect(spy).toHaveBeenNthCalledWith(1, 1, void 0);
expect(spy).toHaveBeenNthCalledWith(2, 2, 1);
});

test('should work signal.trigger from signal', async () => {
const spy = jest.fn();

const s = signal(1);
const r = signal.trigger.from(s);

sync(r, spy);

s(1);
s(3);

expect(spy).toBeCalledTimes(2);
expect(spy).toHaveBeenNthCalledWith(1, 1, void 0);
expect(spy).toHaveBeenNthCalledWith(2, 1, 1);
});

test('should work reset with signal.trigger from signal', async () => {
const spy = jest.fn();

const s = signal(1);
const r = signal.trigger.from(s);

expect(r.val).toBe(1);
sync(r, spy);

s(1);
s(3);

let k;
expect(await (k = r.promise)).toBe(1);

expect(spy).toBeCalledTimes(2);
expect(spy).toHaveBeenNthCalledWith(1, 1, void 0);
expect(spy).toHaveBeenNthCalledWith(2, 1, 1);
spy.mockReset();

r.reset();
expect(r.promise).not.toBe(k);
expect(r.val).toBe(3);

s(1);
s(3);

expect(await r.promise).toBe(1);

expect(r.val).toBe(1);
expect(spy).toBeCalledTimes(2);
expect(spy).toHaveBeenNthCalledWith(1, 3, 1);
expect(spy).toHaveBeenNthCalledWith(2, 1, 3);
});

test('should work signal.trigger.flag from expression', async () => {
const spy = jest.fn();

const v = value(0);
const r = signal.trigger.flag.from(() => v.val as any);

sync(r, spy);

v(1);
v(0);

expect(spy).toBeCalledTimes(2);
expect(spy).toHaveBeenNthCalledWith(1, false, void 0);
expect(spy).toHaveBeenNthCalledWith(2, true, false);
});

test('should work reset with signal.trigger.flag from expression', async () => {
const spy = jest.fn();

const v = value(0);
const r = signal.trigger.flag.from(() => v.val as any);

sync(r, spy);

v(1);
v(0);

expect(spy).toBeCalledTimes(2);
expect(spy).toHaveBeenNthCalledWith(1, false, void 0);
expect(spy).toHaveBeenNthCalledWith(2, true, false);

r.reset();
expect(r.val).toBe(false);
v(1);
expect(r.val).toBe(true);
r.reset();
expect(r.val).toBe(true);

v.reset();
expect(r.val).toBe(false);

expect(await r.promise).toBe(false);
});

test('should work signal.trigger resolved', async () => {
const r = signal.trigger.resolved(1);
expect(r.val).toBe(1);
Expand Down

0 comments on commit c14a0c1

Please sign in to comment.