Guest User

Untitled

a guest
Mar 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. interface WiredActions<S> {
  2. [key: string]: (...args: any[]) => S | WiredActions<S>;
  3. }
  4.  
  5. type GenericState = any;
  6. type Actions = HyperAppActions<GenericState, WiredActions<GenericState>>;
  7.  
  8. function rewriteActions(actions: Actions): Actions {
  9.  
  10. return Object.entries(actions).reduce((accum, [name, action]) => {
  11.  
  12. // dont rewrite the location actions for @hyperapp/router
  13. if (name === 'location') {
  14. return {
  15. ...accum,
  16. [name]: action
  17. };
  18. }
  19.  
  20. return {
  21. ...accum,
  22. [name]: typeof action === 'object' ?
  23. rewriteActions(action) :
  24. (...args1: any[]) => {
  25. return (state: GenericState, actions: BoundActions<GenericState>) => {
  26. const result = action(state, actions);
  27. return result(...args1);
  28. };
  29. }
  30. };
  31. }, {});
  32. }
  33.  
  34. export function withSnoitca(app: App<GenericState, Actions>): App<GenericState, Actions> {
  35. return (state, actions, view, container) => app(state, rewriteActions(actions), view, container);
  36. }
Add Comment
Please, Sign In to add comment