Skip to content

Commit d7f56eb

Browse files
authored
Merge branch 'master' into ft-using-keyof-operator-to-limit-parameter-type
2 parents 1bd1a77 + af6b7fd commit d7f56eb

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"test:only-one": "tsc src/only-one/only-one.ts && vitest src/only-one",
1111
"test:new-skills": "tsc src/new-skills/new-skills.ts && vitest src/new-skills",
1212
"test:constraints": "tsc src/constraints/constraints.ts && vitest src/constraints",
13-
"test:type-operator": "tsc src/type-operator/type-operator.ts && vitest src/type-operator"
13+
"test:type-operator": "tsc src/type-operator/type-operator.ts && vitest src/type-operator",
14+
"test:subscriber": "tsc src/subscriber/subscriber.ts && vitest src/subscriber"
1415
},
1516
"repository": {
1617
"type": "git",

src/subscriber/subscriber.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { test, expect } from 'vitest';
2+
3+
import { db } from './subscriber';
4+
5+
test('db should have users, articles, photos, and subscribe properties', () => {
6+
expect(db).toHaveProperty('users');
7+
expect(db).toHaveProperty('articles');
8+
expect(db).toHaveProperty('photos');
9+
expect(db).toHaveProperty('subscribe');
10+
});
11+
12+
test('db.subscribe should return the event', () => {
13+
const event = 'usersCreated';
14+
const callback = () => {};
15+
expect(db.subscribe(event, callback)).toBe(event);
16+
});

src/subscriber/subscriber.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export interface User {
2+
id: number;
3+
firstName: string;
4+
lastName: string;
5+
}
6+
7+
export interface Article {
8+
id: number;
9+
title: string;
10+
content: string;
11+
}
12+
13+
export interface Photo {
14+
id: number;
15+
url: string;
16+
}
17+
18+
export type CRUDEvent = 'created' | 'read' | 'updated' | 'deleted';
19+
20+
interface Database {
21+
users: User[];
22+
articles: Article[];
23+
photos: Photo[];
24+
}
25+
26+
export const db: SubscribableDatabase<Database> = {};
27+
28+
db.subscribe<'users'>('usersCreated', (users) => {});
29+
db.subscribe<'articles'>('articlesRead', (articles) => {});

0 commit comments

Comments
 (0)