This package has been deprecated

Author message:

@ragg/fleur is deprecated, use @fleur/fleur instead

@ragg/fleur
TypeScript icon, indicating that this package has built-in type declarations

0.0.17 • Public • Published

🌼 Fleur 🌼 npm version travis

An Fully-typed Flux framework inspired by Fluxible. Runs on Node / Web.

(No dependence to React. see this if you want to use with React.)

Example

// actions.ts (Action typings)
import { action } from '@ragg/fleur'

export const CounterActions = actions('CounterAction', {
    increase: action<{ amount: number }>(),
    decrease: action<{ amount: number }>(),
}
// store.ts (Store)
import { listen, Store } from '@ragg/fleur'
import { CounterActions } from './actions.ts'

export default class SomeStore extends Store {
    public state: { count: number } = { count: 0 }

    private handleIncrease = listen(CounterActions.increase, (payload) => {
        // `this.updateWith` is immutable changing `this.state` with `immer.js`
        this.updateWith(draft => draft.count += payload.amount)
    })

    private handleDecrease = listen(CounterActions.decrease, (payload) => {
        this.updateWith(draft => draft.count -= payload.amount)
    })

    public getCount() {
        return this.state.count
    }
}
// operations.ts (Action Creator)
import { operation } from '@ragg/fleur'
import { CounterActions } from './actions.ts'

export const increaseOperation = operation((ctx, { amount }: { amount: number }) => {
    ctx.dispatch(CounterActions.increase, { amount })
})

export const decreaseOperation = operation((ctx, { amount }: { amount: number }) => {
    ctx.dispatch(CounterActions.decrease, { amount })
})
// app.ts
import Fleur from '@ragg/fleur'
import SomeStore from './store.ts'

const app = new Fleur({
    stores: [SomeStore],
})

const ctx = app.createContext()
ctx.executeOperation(increaseOperation, { amount: 10 })
console.log(ctx.getStore(SomeStore).getCount()) // => 10

How to use with React?

See @ragg/fleur-react.

Readme

Keywords

none

Package Sidebar

Install

npm i @ragg/fleur

Weekly Downloads

1

Version

0.0.17

License

MIT

Unpacked Size

24.7 kB

Total Files

30

Last publish

Collaborators

  • ragg