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

adss

v1.0.5

Published

Action->Dispatch->Services->Store flow

Downloads

2

Readme

ADSS

Action->Dispatch->Services->Store flow

Installation

npm install --save adss

API

createLogic(initState, services, servicesFactories)

import { createLogic } from 'adss'
const logic = createLogic()

You can set initial state, your own services and servicesFactories:

import { createLogic, services, servicesFactories } from 'adss'
const initialState = {}
const myServices = {
    ...services,
    log: (text) => console.log(text)
}
const myServicesFactories = {
    ...servicesFactories,
    logState: (services, dispatchContext) => {
        dispatchContext.myCounter = 1
        return () => console.log(dispatchContext.myCounter, dispatchContext.getState())
    }
}
const logic = createLogic(initialState, myServices, myServicesFactories)

logic.getState()

logic.getState()

logic.dispatch(action):

const action = actions.action1(value1, value2) 
logic.dispatch(action)

Action is a function that call available services

const actionX = (services) => {
    const { getState, setState, dispatch, serviceX, ...otherServices }  = services
    const state = getState()
    setState((state) => ({...state, v1: arg1}) ) 
    dispatch(actionY) //dispatch another action
    serviceX()  //call your own service
}

For create actions use HOF:

const initValue = () => ({ setState }) => {
    setState((state) => ({...state, v1: 0}) ) 
}
const incrementValue = (v) => ({ setState }) => {
    setState((state) => ({...state, v1: state.v1 + v}) ) 
}
const multiplyValue = (v) => ({ setState }) => {
    setState((state) => ({...state, v1: state.v1 * v}) ) 
}
const incMultValue = (inc, mult) => ({ dispatch }) => {
    dispatch(incrementValue(inc))
    dispatch(multiplyValue(mult))
}
const incMultValueOnce = (inc, mult) => ({ hold }) => { 
    hold(({ dispatch }) => {
        dispatch(incrementValue(inc))
        dispatch(multiplyValue(mult))
    })
}

logic.subscribe(callback)

You can use callback if you want to change something each time when store changed

const onStateChangeCallback = (state) => conslole.log(state)
logic.subscribe(onStateChangeCallback)

logic.unsubscribe(callback)

Callback will help if we need rerender something in view each time when state change

const onStateChangeCallback = (state) => conslole.log(state)
logic.subscribe(onStateChangeCallback)
// dispatch any actions
logic.unsubscribe(onStateChangeCallback)

How organize business logic of the application

It is proposed to use one file to aggregate logic of one area of the business logic. This file contains:

  • Updater
  • Selectors
  • Actions
  • Init Action

Updater part of the module X

export const updater = (reducer) => (store) => ({...store, moduleX: reducer(store.moduleX)})

This is HOF that describe how to update main store. It get global state and return new one with changed only one part. You can use immutable js or other libraries for implement this

Selectors part of the module X

export const selector = (store) => store.moduleX
export const selectPartXSum = (store) => store.moduleX.v1 + store.moduleX.v2

This function describe how to select part from the main store. You can use reselect or other libraries for implement this

Actions part of the module X

const stateAction = (reducer) => ({setState}) => setState(updater(reducer))

const incrementValue = (v) => stateAction((state) => ({...state, v1: state.v1 + v}) )

const multiplyValue = (v) => stateAction((state) => ({...state, v1: state.v1 * v}) )

const incMultValue = (inc, mult) => ({ dispatch }) => {
    dispatch(incrementValue(inc))
    dispatch(multiplyValue(mult))
}

const incMultValueOnce = (inc, mult) => ({ hold }) => { 
    hold(({ dispatch }) => {
        dispatch(incrementValue(inc))
        dispatch(multiplyValue(mult))
    })
}

These is action creators that return actions. Action use defined services for change state

Init actions part of the module X

const init = () => stateAction((state) => ({...state, v1: 0}) )

This is init action creator. You should dispatch it when init application

Combine modules of the bussines logic

import { createLogic } from 'adss'
import { moduleX } from './moduleX'
const logic = createLogic()
logic.dispatch(moduleX.init())
const render = (state) => {
  //rerender view
} 
logic.subscribe(renderer)

logic.dispatch(actions.initValue())
// render call once


logic.dispatch(actions.incMultValue(2,5))
// render call twice
// because setState service will call twice


logic.dispatch(actions.incMultValueOnce(2,5))
// render call once
// because 'setState' service held by 'hold' service

Connect to React

Use npm module react-adss

Write custom services

todo

License

MIT