store

package
v2.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package store is the dirty part of whole Redux system. But also is the main logic place

The purpose is providing a place that you can just dispatch action to it. Without consider the complex behind it

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a type manage your data

Usage:

counter := func(state int, payload int) int {
    return state + payload
}
store := store.New(counter)
store.Dispatch(30)
fmt.Printf("%d\n", store.StateOf(counter)) // expected: 30

func New

func New(reducers ...interface{}) *Store

New create a Store by reducers

func (*Store) Dispatch

func (s *Store) Dispatch(action interface{})

Dispatch send action to reducers in Store to update state

In v2, action can be anything you want

For example:

func counter(state, payload int) int {
	return state + payload
}

Action type should be `int`, if you use others type, just use others type

func (*Store) StateOf

func (s *Store) StateOf(reducer interface{}) interface{}

StateOf return the reducer matches state

func (*Store) Subscribe

func (s *Store) Subscribe(function func())

Subscribe emit a function will be triggered after executing Dispatch

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL