Refactored App component in front. Implemented pnpm workspaces. Separated messages types into package

This commit is contained in:
2021-09-04 19:16:22 +03:00
parent 0328b4d3d1
commit 8be147c3b8
36 changed files with 152 additions and 81 deletions

View File

@@ -0,0 +1,13 @@
{
"name": "@roomruler/messages",
"main": "dist/src/index.js",
"version": "0.0.0",
"types": "dist/src/index.d.ts",
"scripts": {
"build": "tsc --build"
},
"devDependencies": {
"typescript": "^4.4.2"
},
"private": "true"
}

View File

@@ -0,0 +1,33 @@
export type Message = {
type: string;
args: unknown;
};
export type UpdateMessage = Message & {
type: "update";
args: {
id: number;
value: boolean;
};
};
const isObjLike = (obj: unknown): obj is object =>
Boolean(obj) && typeof obj === "object";
const hasProperty = <T extends {}, U extends PropertyKey>(
obj: T,
prop: U
): obj is T & Record<U, unknown> => prop in obj;
export const isMessage = (obj: unknown): obj is Message =>
isObjLike(obj) &&
hasProperty(obj, "type") &&
typeof obj.type === "string" &&
hasProperty(obj, "args");
export const isUpdateMessage = (message: Message): message is UpdateMessage =>
isObjLike(message.args) &&
hasProperty(message.args, "id") &&
typeof message.args.id === "number" &&
hasProperty(message.args, "value") &&
typeof message.args.value === "boolean";

View File

@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "dist",
"composite": true
},
"include": ["src"]
}