Git Product home page Git Product logo

hyperapp-logger's Introduction

Hyperapp Logger

Travis CI Codecov npm Slack

A Hyperapp higher-order app that logs state updates and action information to the console.

Getting Started

This example shows a counter that can be incremented or decremented. Go ahead and try it online with your browser console open to see the log messages.

import { h, app } from "hyperapp"
import { withLogger } from "@hyperapp/logger"

const state = {
  count: 0
}

const actions = {
  down: () => state => ({ count: state.count - 1 }),
  up: () => state => ({ count: state.count + 1 })
}

const view = (state, actions) => (
  <main>
    <h1>{state.count}</h1>
    <button onclick={actions.down} disabled={state.count <= 0}></button>
    <button onclick={actions.up}></button>
  </main>
)

withLogger(app)(state, actions, view, document.body)

Screenshot

Installation

Node.js

Install with npm / Yarn.

npm i @hyperapp/logger

Then with a module bundler like rollup or webpack use as you would anything else.

import { withLogger } from "@hyperapp/logger"

Browser

Download the minified library from the CDN.

<script src="https://unpkg.com/@hyperapp/logger"></script>

You can find the library in window.hyperappLogger.

const { withLogger } = hyperappLogger

Usage

Compose the withLogger function with your app before calling it with the usual arguments.

import { withLogger } from "@hyperapp/logger"

withLogger(app)(state, actions, view, document.body)

// Or if you need to pass options
withLogger(options)(app)(state, actions, view, document.body)

Options

options.log

Use it to customize the log function.

withLogger({
  log(prevState, action, nextState) {
    // format and send your log messages anywhere you like
  }
})(app)(state, actions, view, document.body)

License

Hyperapp Logger is MIT licensed. See LICENSE.

hyperapp-logger's People

Contributors

okwolf avatar jorgebucaran avatar joseluisq avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.