Created
March 8, 2018 05:32
-
-
Save maxholman/38569b50c123120b85d45c6807c6a816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment