Skip to content

Instantly share code, notes, and snippets.

@sergey-shpak
Created June 13, 2019 12:10
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 sergey-shpak/29f1f5733715fedb265662d2f327ee8c to your computer and use it in GitHub Desktop.
Save sergey-shpak/29f1f5733715fedb265662d2f327ee8c to your computer and use it in GitHub Desktop.
Hyperapp#2 dispatch logger
import { h, app } from 'hyperapp'
import { logger } from 'helpers/logger'
const init = () => ({ initalized: true })
app({ init }, logger(process.env.NODE_ENV==='development'))
const isArray = Array.isArray
const isFunction = param => typeof param === 'function'
export const logger = (env, output = console.debug) =>
env && (dispatch => (action, props, obj) => {
if(isFunction(action))
output('Action', action.name, props, obj)
else if(isArray(action)){
// 'tuple action' logged with next dispatch iteration
if(isArray(action[1]))
output('Effect', action[1][0].name, action[1][1])
} else output('State', action)
return dispatch(action, props, obj)
})
export default logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment