Last active
November 13, 2017 18:27
-
-
Save robinpokorny/c1f049f815ec274fdedbb454c56d74ee to your computer and use it in GitHub Desktop.
A simple Hyperapp v0.16.0 logger for debugging
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
/* | |
* Include after hyperapp.js and before your app | |
* Use this version provided by rawgit.com: | |
* https://cdn.rawgit.com/robinpokorny/c1f049f815ec274fdedbb454c56d74ee/raw/hyperapp-logger.js | |
*/ | |
const mapValue = (object, iteratee) => { | |
// https://github.com/lodash/lodash/blob/master/mapValue.js | |
object = Object(object); | |
const result = {}; | |
Object.keys(object).forEach(key => { | |
result[key] = iteratee(object[key], key, object); | |
}); | |
return result; | |
}; | |
const debug = app => (props, container) => { | |
console.log('HYPERAPP DEBUG MODE'); | |
const actions = mapValue( | |
props.actions, | |
(fn, key) => (state, actions) => (...args) => { | |
const stateDiff = fn(state, actions)(...args); | |
console.log(key, state, stateDiff, ...args); | |
return stateDiff; | |
} | |
); | |
return app(Object.assign({}, props, { actions }), container); | |
}; | |
hyperapp.app = debug(hyperapp.app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment