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

ux-redux-module

v2.1.1

Published

面向对象redux, [在线 demo](https://hahahahx.github.io/ux-redux-module/), [demo源码](https://github.com/Hahahahx/ux-redux-module/tree/master/example)

Downloads

24

Readme

ux-redux-module

面向对象redux, 在线 demo, demo源码

React, hook, 函数组件


在该项目的状态管理中,约束用户必须采用面向对象的形式来编写,这有助于 更好的管理项目,面向对象的形式使我们更能清晰的看见状态的结构。

@Module
class FileModule extends BaseModule {

    @LocalStorage
    @SesstionStorage
    filename = 'FileModule';

    @SesstionStorage
    fileType = 'txt' 
 

    reqFilebyUpdate() {
        this.filename = 'FileModule被Update更新了';
        this.fileType = 'update'
        this.update()
    }
}

模块类需要继承基础模块BaseModule,以及加装饰器@Module,之后可以在类内部使用this.update()方法来提交该模块状态的更新

@SessionStorage@LocalStorage装饰的字段会被注册到内存和本地中。 提供了deleteSession(property:string)deleteLocal(property:string)可以让你自由的删除他们。 你需要确保你不会在你的事件流中使用到被删除的属性。因为被装饰的属性会不断的在更新状态中更新对应的Local或Session

引入:


const module = { FileModule }; 
ReactDOM.render(
    <ReduxProvider value={module}>
        <div>可以刷新网页,对状态加了 @SesstionStorage 会保存到SesstionStorage中</div>
        <App />
    </ReduxProvider>,
    document.getElementById("root")
);

引入ReduxProvider,传入状态module,可以对module推测类型,方便后续在组件中更好的使用。

在组件中使用:


const Main = () => {

    const fileModule = useModule(FileModule)

    return (
        <div style={{ textAlign: 'center' }}>
            <div className='page'>
                FileModule-filename:{fileModule.filename}
            </div>
            <Button ghost onClick={() => {
                fileModule.reqFile()
            }}>ChangeFileModuleByAction</Button>
            <Button ghost onClick={() => {
                fileModule.reqFilebyUpdate()
            }}>ChangeUserModuleByUpdate</Button>
        </div>
    )
}