Skip to content

Commit

Permalink
updates for beta.13
Browse files Browse the repository at this point in the history
  • Loading branch information
okwolf committed May 28, 2019
1 parent 37604bd commit f22a74c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "hyperapp-compat",
"version": "0.3.0",
"version": "0.4.0",
"description": "v2 features in your v1 Hyperapps",
"main": "dist/hyperappCompat.js",
"module": "src/index.js",
Expand Down
29 changes: 15 additions & 14 deletions src/index.js
Expand Up @@ -49,24 +49,25 @@ export default function withCompat(nextApp) {
props.actions[INTERNAL_SET_STATE] = Function.prototype;

var wiredActions;
function dispatch(obj, props) {
function dispatch(action, props, obj) {
var state = wiredActions[INTERNAL_GET_STATE]();
function setState(nextState) {
wiredActions[INTERNAL_SET_STATE](nextState);
}
if (isFn(obj)) {
dispatch(obj(state, props));
} else if (isArray(obj)) {
if (isFn(obj[0])) {
dispatch(obj[0](state, obj[1], props));
} else {
flatten(obj.slice(1)).map(function(fx) {
fx && fx[0](fx[1], dispatch);
}, setState(obj[0]));
}
} else {
setState(obj);
}
return isFn(action)
? dispatch(action(state, props), obj || props)
: isArray(action)
? isFn(action[0])
? dispatch(
action[0],
isFn((action = action[1])) ? action(props) : action,
props
)
: (flatten(action.slice(1)).map(function(fx) {
fx && fx[0](dispatch, fx[1], props);
}, setState(action[0])),
state)
: setState(action);
}

var enhancedActions = makeEnhancedActions(
Expand Down
2 changes: 1 addition & 1 deletion src/patchSub.js
Expand Up @@ -18,7 +18,7 @@ export default function patchSub(sub, newSub, dispatch) {
out.push(
b
? !a || b[0] !== a[0] || shouldRestart(b[1], a[1])
? [b[0], b[1], b[0](b[1], dispatch), a && a[2]()]
? [b[0], b[1], b[0](dispatch, b[1]), a && a[2]()]
: a
: a && a[2]()
);
Expand Down

0 comments on commit f22a74c

Please sign in to comment.