Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
divdavem committed Jun 13, 2024
1 parent 4224222 commit c34a194
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 528 deletions.
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 @@ -444,34 +444,6 @@ describe('stores', () => {
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 @@ -1602,7 +1574,7 @@ describe('stores', () => {
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 @@ -1621,7 +1593,7 @@ describe('stores', () => {
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 @@ -2987,7 +2959,7 @@ describe('stores', () => {
const values: number[] = [];
expect(() => {
myValue.subscribe((value) => values.push(value));
}).toThrowError('recursive computed');
}).toThrowError('Detected cycle in computations.');
expect(values).toEqual([]);
});

Expand All @@ -2999,7 +2971,7 @@ describe('stores', () => {
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 @@ -3014,7 +2986,7 @@ describe('stores', () => {
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 @@ -3033,7 +3005,7 @@ describe('stores', () => {
});
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

0 comments on commit c34a194

Please sign in to comment.