Skip to content

Instantly share code, notes, and snippets.

@robinpokorny
Last active November 13, 2017 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinpokorny/c1f049f815ec274fdedbb454c56d74ee to your computer and use it in GitHub Desktop.
Save robinpokorny/c1f049f815ec274fdedbb454c56d74ee to your computer and use it in GitHub Desktop.
A simple Hyperapp v0.16.0 logger for debugging
/*
* 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