vuex

package
v0.0.0-...-36a01d3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Stores are all Vuex stores that the Go ecosystem knows about. All actions
	// that are defined for each store have to be registered in the JS Vuex store
	// under the same name and be redirected to the Go implementation using the
	// `CohorseVuexDispatch` JS function.
	// TODO: Add generator which creates the JS stubs for the actions.
	Stores = StoreIndex{
		"global": NewStore(func() js.Value {

			return js.Global().Get("store")
		}, ActionIndex{
			"setSysInfo": Action(func(s Store, payload interface{}) {
				s.Commit("setSysInfoVersion", sysinfo.Version)
				s.Commit("setSysInfoBuild", sysinfo.Build)
				s.Commit("setSysInfoCommit", sysinfo.Commit)
				s.Commit("finishAppLoading", nil)
			}),
		}),
	}
)

Functions

func ExposeDispatchActionFromJS

func ExposeDispatchActionFromJS()

ExposeDispatchActionFromJS exposes the Action Dispatch function to the global JS namespace under the key `CohorseVuexDispatch`.

Types

type Action

type Action func(s Store, payload interface{})

Action is a Vuex action function that can be dispatched directly from Go or using the `CohorseVuexDispatch` function in JS.

type ActionIndex

type ActionIndex map[string]Action

ActionIndex is the index of all known stores. Actions are scoped per store.

type ActionResponse

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

ActionResponse is the structure in which the action response is encoded.

func (ActionResponse) JSValue

func (resp ActionResponse) JSValue() js.Value

JSValue encodes the response of the action into a JS value which can be passed back to the JS frontend. Any non-nil error will be represented by a string of its message.

type ActionResponsePayload

type ActionResponsePayload interface {
	JSValue() js.Value
}

ActionResponsePayload has to be implemented by every payload that is returned by an action.

type Store

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

Store is a Vuex store which can be used to dispatch actions or commit mutations. It stores the underlying JS object and all actions which are implemented in Go and can be dispatched using the `CohorseVuexDispatch` from JS.

func NewStore

func NewStore(sf StoreObjectFunc, actions ActionIndex) Store

NewStore creates a new Store and uses the store object function to retrieve the JS object of the Vuex store.

func (Store) Commit

func (s Store) Commit(mType string, payload interface{})

Commit commits a mutation on the given store. The payload may be supplied but is optional. The actual state mutation is performed within JS.

func (Store) Dispatch

func (s Store) Dispatch(aType string, payload interface{}) error

Dispatch dispatches an action on the given store. The payload may be supplied but is optional.

type StoreIndex

type StoreIndex map[string]Store

StoreIndex is the index of all known stores.

type StoreObjectFunc

type StoreObjectFunc func() js.Value

StoreObjectFunc has to be supplied to the `NewStore` function. It has to return the JS object for the new Vuex store.

Jump to

Keyboard shortcuts

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