Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export type Change<S, M> = [S, Effect<M>?];

export interface Effect<M> {
(dispatch: Dispatch<M>): void;
}

export interface Update<M, S> {
(message: M, state: S): Change<S, M>;
}

export interface View<M, S, V> {
(state: S, dispatch: Dispatch<M>): V;
}

export interface Dispatch<M> {
(message: M): void;
}

export interface Done<S> {
(state: S): void;
}

export interface Program<S, M, V> {
readonly init?: Change<S, M>;
readonly update: Update<M, S>;
readonly view: View<M, S, V>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue with generic V is that for raj/runtime view is <State, Message>(state: State, dispatch: Dispatch<Message>): void as Raj does nothing with the return value. The return value of view is given meaning in the view libraries such as raj-react. Typing this we either over generalize the core framework or have multiple Program definitions that end-users would need to reconcile.

I'm not saying this is wrong, just something to consider.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this only makes sense if we consider raj-react or similar packages. I've already made typings for raj-react so I'll make a similar PR to that repo in order to put the generic V in context for discussing these typings.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the typings for raj-react to put theV in context are here. Not sure if it is really needed, maybe it could be done somehow without V.

readonly done?: Done<S>;
}

export function runtime<S, M, V>(program: Program<S, M, V>): void;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"scripts": {
"lint": "fixpack && prettier index.js test/**/*.js --write && standard --fix",
"test": "npm run lint && ava"
}
},
"types": "index.d.ts"
}