Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
divdavem committed Sep 12, 2024
1 parent 673ebcd commit dc5d813
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 527 deletions.
9 changes: 9 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#d9d4cce78f0391b646a8a68553b9e94355681eb0"
},
"private": true,
"devDependencies": {
"@angular/common": "^18.2.3",
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 @@ -1601,7 +1573,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 @@ -1620,7 +1592,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 @@ -2986,7 +2958,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 @@ -2998,7 +2970,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 @@ -3013,7 +2985,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 @@ -3032,7 +3004,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 dc5d813

Please sign in to comment.