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

duxter

v0.0.1

Published

A small 1kb and simple centralized state management for Javascript applications.

Downloads

7

Readme

duxter is a small 1kb and simple centralized state management for Javascript applications.

npm package CDN

Influences

Dux provides more control of your application state. It's envolve ideas of ReDuxter and Flux, but explores all power of Promises, doing the work with async action easy.

Getting Started

Install

  • Npm: npm install duxter
  • Bower: bower install duxter
  • CDN: https://unpkg.com/[email protected]

Features

  • small 1kb minified & gzipped
  • simple, small learning curve
  • immutable
  • promise based
  • inspired on ReDuxter
  • tiny API.

The Gist

The application state is stored in an object tree inside a single store. You can receive the result of your action using .then after your dispatch call.

That's it!

import { setState, subscribe, dispatch, getState } from 'duxter';

/**
 * Set your store state in a single object.
 */
setState({
 count: 1
})

/**
 * Set your store state in a single object,
 * that always receive the store state as first argument.
 */
function increment(value) {
  const { count } = getState()
  return { type: 'INCREMENT', value: count + value }
}

/**
 * You can use subscribe() to update your UI in response to state changes.
 * `${this}` can be your UI component, where the subscribe handler will be applied.
 */
subscribe( this, ( {type, value } ) => {
  console.log(`Some action was called, the action type: ${type} and the action value: ${value}.`);
})

/**
 * The only way to mutate the internal state is to dispatch an action.
 * You can receive the response of your action and do something, or not.
 */
dispatch(increment(1)).then( {type, value} => {
    console.log(`The value is: ${value}`);
})// 2
dispatch(increment(2)); // 3
dispatch(increment(3));// 4

console.log(getState().count) // 1

Simple and efficiently API.

Dispatch

  • Trigger some action for do something. A Promise will be returned, that contain an Object with the keys action and value of your correspondent action response.
/**
 * @name dispatch
 * @description Trigger some action.
 * @param {string} actionName Action name
 * @param { arguments } Arguments You can pass the arguments after the actionName
 * @return {Promise} Return a Promise with an Object that contain the value 
 * of the action and the action name. 
 * {value, action} = data;
 */

// On your component
import {dispatch} from 'duxter';

// You can receive the response of your action and do something, or not.
// If you whant, you can chaining the dispatch Promises.
dispatch(increment(1))
  .then( data => {
  console.log(`Some action was called, the action type: ${type} and the action value: ${value}.`);
  });

Actions

  • Actions are payloads of information that send data from your application to your store. They are the only source of information for the store. You send them to the store using store.dispatch().

Store State

  • Set the application Store state
/**
 * @name setState
 * @description Set you application store state
 * @param {object} state Your application state data
 */
 
import {setState} from 'duxter';

setState({
  count: 1
});

Getting the Store State

  • Get a state value of your store
/**
 * @name getState
 * @description Get the state value
 */
 
import {getState} from 'duxter';

getState(); // returns a copy of your store state

Middleware

  • Set a middleware function, that will be triggered after the action calls.
/**
 * @name middleware
 * @description Get the state value
 * @param {Function} callback The function that will be triggered when
 * you use the dispatch method. Receives your payload
 */
 
import { middleware } from 'duxter';

middleware( action  => {
    console.log(action);
})

Subscribe/Unsubscribe

  • Subscribe some UI Component for trigger the handler function when some action are trigger.
  • Unsubscribe when you don't wnat to trigger the handler function.
/**
 * @name subscribe
 * @description Subscribe some UI Component for trigger the handler function when some action calls.
 * @param { object } BindComponent The UI element that the handler function will be applied.
 * @param { handler } handler Your function that will be triggered when some state change.
 */
 
import {subscribe, unsubscribe, getState} from 'duxter';
  
  componentWillMount(){
     // when some state change, do something.
     subscribe(this, ({value}) => {
       this.setState({count: value})
     });
  }
  
    componentWillUnmount(){
      // remove this component for observe the changes on the state
      unsubscribe(this)
    }

License

MIT License.