npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xfx

v1.2.1

Published

A simple abstraction over virtual-dom

Downloads

17

Readme

xfx -> No Framework

Build Status

This is a simple abstraction over the virtual-dom to make it easy to build component architected applications:

A component architecture uses composable components to build sophisticated applications, this module, only enables this ability, it pushes other opinions like routing and transitions to other libraries.

What is a component?

A component is a composable module that consists of the following:

  • init function (Model)
  • render function (View)
  • actions object (Update)

This structure makes it very easy to create tree like structures of these composable components and weave together a very sophisticated application.

main.js component

var app = require('xfx')
var h = app.h // virtual hyperscript
var bindState = app.bindState


module.exports = component
component.render = render

function component () {
  // define my state
  var state = {
    foo: 'baz'
  }

  // initialize actions
  state.actions = bindState(actions())
  return state
}

function actions () {
  return {
    foo: function (state) {
      state.foo = 'bar'
      // repaint
      app.update()
    }
  }
}

function render (state) {
  return h('div', [
    h('h1', 'Hello World'),
    h('button', {
      'ev-click': sendClick(state.actions.foo)
    }, state.foo)
  ])
}

index.js

// vdom-arc
var app = require('xfx')

// always start with root component
var main = require('./components/main')
// run app
app(main)

API

app([default init function with render function], [optional target])

This function takes in the main or root component, this component should have a default handler that receives the state and update objects and returns a state object.

var app = require('xfx')
var h = app.h

main.render = render
app(main)

function main (state, update) {
  return state
}

function render (state) {
  return h('h1', 'Hello World')
}

app.h [hyperscript]

The h method is an alias to virtual-hyperscript

virtual-hyperscript is a simple javascript module that create VTree notation for the virtual dom engine, it is a very expressive api to create markup, it also is very functional friendly.

function li (widget) {
  return h('li', widget.name)
})

return h('ul', widgets.map(li))
<ul>
  <li>foo</li>
  <li>bar</li>
</ul>

app.update

The app.update command should be called when the state changes within the component actions or within the component initialization method. The update method will take the current state and apply it to the DOM calling the render method.

function actions () {
  return {
    click: function (state) {
      state.title = 'foo'
      app.update()
    }
  }
}

app.bindState

bindState is a helper method that can be used to bind actions from your component to handle the components state when a click, or submit occurs.

function component () {
  var state = {}
  state.actions = bindState(actions())
  return state
}

function actions () {
  return {
    click: function (state) {
      // do stuff
    }
  }
}

These are value-event handlers that manage the event listen and removing for you so you don't have to worry about boilier plate code and the need to add and remove listeners.

app.send

The send method is the generic event method, if you want to capture all of the events of a given component, then you can use the send method to ev-event object.

  h('div', { 'ev-event': send(fn) } )

app.sendValue

The sendValue will send the value of an input element whenever the listener fires but it does not have special semantics of what's a valid event.

https://github.com/Raynos/value-event#example-value

app.sendChange

The sendChange event happens when form elements change.

see: https://github.com/Raynos/value-event#example-change

app.sendClick

The sendClick event fires whenever a click occurs on an element.

https://github.com/Raynos/value-event#example-event

app.sendSubmit

The sendSubmit fires when a form is submitted.

https://github.com/Raynos/value-event#example-submit

app.sendKey

The sendKey enables you to specify a key to listen for and then the event fires when that key is pressed.

  var UP = 38
  var DOWN = 40
  var ENTER = 13

  h('input', {
    'ev-keydown': [
      sendKey(state.actions.move, 'down', { key: DOWN}),
      sendKey(state.actions.move, 'up', { key: UP}),
      sendKey(state.actions.select, 'select', { key: ENTER })
      ]
  })

app.delegator

The delegator helper is great for adding global event listeners.

Examples

see /examples

Contributors

Support

License

MIT