Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface WiredActions<S> {
- [key: string]: (...args: any[]) => S | WiredActions<S>;
- }
- type GenericState = any;
- type Actions = HyperAppActions<GenericState, WiredActions<GenericState>>;
- function rewriteActions(actions: Actions): Actions {
- return Object.entries(actions).reduce((accum, [name, action]) => {
- // dont rewrite the location actions for @hyperapp/router
- if (name === 'location') {
- return {
- ...accum,
- [name]: action
- };
- }
- return {
- ...accum,
- [name]: typeof action === 'object' ?
- rewriteActions(action) :
- (...args1: any[]) => {
- return (state: GenericState, actions: BoundActions<GenericState>) => {
- const result = action(state, actions);
- return result(...args1);
- };
- }
- };
- }, {});
- }
- export function withSnoitac(app: App<GenericState, Actions>): App<GenericState, Actions> {
- return (state, actions, view, container) => app(state, rewriteActions(actions), view, container);
- }
Add Comment
Please, Sign In to add comment