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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-function-order

v0.1.9

Published

![logo](https://pic.imgdb.cn/item/625a4d6b239250f7c55b4257.png)

Downloads

2

Readme

logo

简体中文

It provides a more standardized, efficient and easy to test functional programming method.

why create the lib

Front-end development is always accompanied by events, IO operations and logic processing. These restrictions usually lead to scattered logic and difficult code testing and maintenance.

Benefits

  • Describe a business logic with classes

  • Support integration status management

  • Convert logic from imperative to declarative

  • Easy to test

  • Make code clean

quick start

react

    npm i react-function-order -S   // or yarn add react-function-order -S   

online demo

Online Supermarket

how it works

流程图

how to use

The simplest use

   import {useFunctionOrderState} from 'react-function-order'

    class JustFnAction {
    
        plus(num) {
            return 1 + num
        }
    
        square(num) {
            return Math.pow(num, 2)
        }
    
        minus(num) {
            return num - 2
        }
    }
    function App() {
        const {actionState, foIns} = useFunctionOrderState({action: JustFnAction})
        useEffect(() => {
            foIns.run(2)
        }, [])
    
        useEffect(() => {
            console.log('actionState Change', actionState)
            // actionState Change {}
            // actionState Change {getActionResult: 7}
        }, [actionState])
    
        return (
            <div className="App">
                {actionState['getActionResult']}
            </div>
        )
    }

If we change minus and Square to asynchronous functions

   import {useFunctionOrderState} from 'react-function-order'
    class FnReturnPromiseAction {
        plus(num) {
            return 1 + num
        }
    
        square(num) {
            return new Promise((resolve => {
                setTimeout(() => {
                    resolve(Math.pow(num, 2))
                },100)
            }))
        }
    
        minus(num) {
            return new Promise((resolve => {
                setTimeout(() => {
                    resolve(num - 2)
                }, 200)
    
            }))
        }
    }
    function App() {
        const {actionState, foIns} = useFunctionOrderState({action: FnReturnPromiseAction})
        useEffect(() => {
            foIns.run(2)
        }, [])
    
        useEffect(() => {
            console.log('actionState Change', actionState)
            // actionState Change {}
            // actionState Change {getActionResult: 7}
        }, [actionState])
    
        return (
            <div className="App">
                {actionState['getActionResult']}
            </div>
        )
    }

react-function-order will automatically execute asynchronous functions in synchronous order for us

Execute multiple parallel asynchronous functions whenrun

  1. The functions between parallel and asynchronous functions are still executed in turn
   import {useFunctionOrderState,InitKeys} from 'react-function-order'

    class PromiseIndependentAction {
        init() {
            return {
                // Declare the functions's names that need to store the result
                [InitKeys.saveResultNames]: ['storeMotoName', 'storeLocation'],
                // Declare flat async functions name
                [InitKeys.flatAsyncNames]: ['getPopularMotoByBrand', 'getLocationByBrand']
            }
        }
    
        getPopularMotoByBrand(brand) {
            return new Promise((resolve => {
                setTimeout(() => {
                    const map = {
                        'honda': 'honda cm300',
                        'suzuki': 'gsx250r'
                    }
                    resolve(map[brand])
                }, 30)
    
            }))
        }
    
        storeMotoName(res) {
            return res
        }
    
        getLocationByBrand(brand) {
            return new Promise((resolve => {
                setTimeout(() => {
                    const map = {
                        'honda': 'Japan',
                        'suzuki': 'Japan',
                        'BMW': 'Ger'
                    }
                    resolve(map[brand])
                }, 30)
            }))
        }
    
        storeLocation(res) {
            return res
        }
    }
    function App() {
        const {actionState, foIns} = useFunctionOrderState({action: PromiseIndependentAction})
        useEffect(() => {
            foIns.run('suzuki')
        }, [])
    
        useEffect(() => {
            console.log('actionState Change', actionState)     
            //{
            // storeMotoName:"gsx250r",
            //  storeLocation:'Japan'
            // }
        }, [actionState])
    
        return (
            <div className="App">
                {actionState['storeMotoName']}
            </div>
        )
    }

We can declare flatAsyncNames in the init function and mark them as asynchronous functions executed in parallel. The functions after these functions will still be executed in turn. Now there are two results. We need to use two keys to store them.

Therefore, we can declare the function that stores the value in saveResultNames and use it as a key.

  1. An asynchronous function returns promises executed in parallel
   import { useFunctionOrderState } from 'react-function-order'
class getMotoAction {
    getBrandNameById(id) {
        return new Promise((resolve => {
            setTimeout(() => {
                const map = {
                    7: 'suzuki',
                    8: 'honda'
                }
                resolve(map[id])
            }, 30)

        }))
    }

    getPopularMotoByBrand(brand) {
        let p = new Promise((resolve => {
            setTimeout(() => {
                const map = {
                    'honda': 'honda cm300',
                    'suzuki': 'gsx250r'
                }
                resolve(map[brand])
            }, 30)
        }))

        let p2 = new Promise((resolve => {
            setTimeout(() => {
                const map = {
                    'honda': 'Japan',
                    'suzuki': 'Japan',
                    'BMW': 'Ger'
                }
                resolve(map[brand])
            }, 30)
        }))
        return [p,p2]
    }
}

function App() {
    const {actionState, foIns} = useFunctionOrderState({action: getMotoAction})
    useEffect(() => {
        foIns.run(7)
    }, [])

    useEffect(() => {
        console.log('actionState Change', actionState)
        //{
        // getActionResult:["gsx250r","Japan"]        
        // }
    }, [actionState])

    return (
        <div className="App">
            {actionState['getActionResult']}
        </div>
    )
}

How can we modify the value stored inactionState(follow the above getMotoAction)

import { useFunctionOrderState,ModifyParams } from "react-function-order"
class ModifyMotoAction {

    modifyActionState(params:ModifyParams){
        const {actionState,runParams} =params
        let actionResult = actionState["getActionResult"]
        actionResult && (actionResult[1]= runParams)
        return actionResult
    }
}
function App() {
    const {actionState, foIns,dispatch} = useFunctionOrderState({action: getMotoAction})
    useEffect(() => {
        foIns.run(7)
    }, [])

    useEffect(() => {
        console.log('actionState Change', actionState)
        // run
        //{
        //  getActionResult:["gsx250r","Japan"]        
        // }
        // handleModify
        //{
        //  getActionResult:["gsx250r","china"]        
        // }
    }, [actionState])
    
    const handleModify = () =>{
        dispatch(ModifyMotoAction,'china')
    }

    return (
        <div className="App">
            <button onClick={handleModify}>modify result</button>
            {actionState['getActionResult']}
        </div>
    )
}

We exposed a dispatch method and passed in action and parameters to modify the actionState

Know more aboutfunctionOrder

Click Here

Change Log

0.1.9 —— add dispatch method in useFunctionOrderState,to modify loaded data 0.1.8 —— Change actionState key from className/methodName to methodName