Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Reimplementing tansu with signal-polyfill #133

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"url": "https://github.com/AmadeusITGroup/tansu/issues"
},
"homepage": "https://github.com/AmadeusITGroup/tansu#readme",
"dependencies": {
"signal-polyfill": "divdavem/signal-polyfill#ef64ffc15daa7553615b4cf8d136a54540423863"
},
"private": true,
"devDependencies": {
"@angular/common": "^18.0.1",
Expand Down
1 change: 1 addition & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export default defineConfig({
},
},
],
external: ['signal-polyfill'],
});
40 changes: 6 additions & 34 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
const store3 = computed(() => store2());
expect(store3()).toBe(0);
store1.set(1);
expect(store3()).toBe(1);

Check failure on line 161 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / build

src/index.spec.ts > stores > base > should work to use subscribe only and use it in a computed

AssertionError: expected +0 to be 1 // Object.is equality - Expected + Received - 1 + 0 ❯ src/index.spec.ts:161:24
});

it('should allow overriding notEqual', () => {
Expand Down Expand Up @@ -444,34 +444,6 @@
unsubscribe();
});

it('should not call again listeners when only resuming subscribers', () => {
class BasicStore extends Store<object> {
public override pauseSubscribers(): void {
super.pauseSubscribers();
}
public override resumeSubscribers(): void {
super.resumeSubscribers();
}
public override set(value: object): void {
super.set(value);
}
}
const initialValue = {};
const newValue = {};
const store = new BasicStore(initialValue);
const calls: object[] = [];
const unsubscribe = store.subscribe((v) => calls.push(v));
expect(calls.length).toBe(1);
expect(calls[0]).toBe(initialValue);
store.pauseSubscribers();
store.resumeSubscribers();
expect(calls.length).toBe(1);
store.set(newValue);
expect(calls.length).toBe(2);
expect(calls[1]).toBe(newValue);
unsubscribe();
});

it('asReadable should be compatible with rxjs (BehaviorSubject)', () => {
const behaviorSubject = new BehaviorSubject(0);
const store = asReadable(behaviorSubject);
Expand Down Expand Up @@ -799,7 +771,7 @@
expect(dependingStore()).toBe(0);
expect(calls).toEqual([1, -1, 1, -1]);
expect(dependingStore()).toBe(0);
expect(calls).toEqual([1, -1, 1, -1, 1, -1]);

Check failure on line 774 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / build

src/index.spec.ts > stores > readable shorthand > should call onUse when reading value and using it in computed

AssertionError: expected [ 1, -1, 1, -1 ] to deeply equal [ 1, -1, 1, -1, 1, -1 ] - Expected + Received Array [ 1, -1, 1, -1, - 1, - -1, ] ❯ src/index.spec.ts:774:21
const unsubscribe = dependingStore.subscribe(() => {});
expect(calls).toEqual([1, -1, 1, -1, 1, -1, 1]);
const unsubscribe2 = dependingStore.subscribe(() => {});
Expand Down Expand Up @@ -1601,7 +1573,7 @@
wrongDerivedStore.subscribe(() => {
reachedSubscriber = true;
});
}).toThrowError('reached maximum number of store changes in one shot');
}).toThrowError('Could not stabilize the computation.');
expect(reachedSubscriber).toBe(false);
});

Expand All @@ -1620,7 +1592,7 @@
expect(values).toEqual([0]);
expect(() => {
store.set(-1);
}).toThrowError('reached maximum number of store changes in one shot');
}).toThrowError('Could not stabilize the computation.');
unsubscribe();
expect(values).toEqual([0]);
});
Expand Down Expand Up @@ -2986,7 +2958,7 @@
const values: number[] = [];
expect(() => {
myValue.subscribe((value) => values.push(value));
}).toThrowError('recursive computed');
}).toThrowError('Detected cycle in computations.');
expect(values).toEqual([]);
});

Expand All @@ -2998,7 +2970,7 @@
expect(values).toEqual([0]);
expect(() => {
recursive.set(true);
}).toThrowError('recursive computed');
}).toThrowError('Detected cycle in computations.');
});

it('should throw when changing a value from computed would result in an infinite loop (on subscribe)', () => {
Expand All @@ -3013,7 +2985,7 @@
wrongComputed.subscribe(() => {
reachedSubscriber = true;
});
}).toThrowError('reached maximum number of store changes in one shot');
}).toThrowError('Could not stabilize the computation.');
expect(reachedSubscriber).toBe(false);
});

Expand All @@ -3032,7 +3004,7 @@
});
expect(() => {
store.set(11);
}).toThrowError('reached maximum number of store changes in one shot');
}).toThrowError('Could not stabilize the computation.');
expect(values).toEqual([0]);
});

Expand Down
Loading
Loading