Skip to content

Latest commit

 

History

History
148 lines (129 loc) · 5.5 KB

API.md

File metadata and controls

148 lines (129 loc) · 5.5 KB

Vunion APIs

Here is a list of all Vunion APIs so that you can use them to research the best way to create your store the way you want to.

Vunion

This is the core module for vunion that exposes the all aspects of the plugin.

import vunion from 'vunion'

The following methods and properties are accessible:

Entry Point Type Usage
store Property Access to the Store API
bus Property Access to the Bus API
install(Vue) Method Vue plugin install method.

Vue calls this when you say: Vue.use(vunion);

version Property The installed version number.

Store

This is the store module that exposes the all interactions with the store.

import vunion from 'vunion';
vunion.store

Or by named export:

import {store} from 'vunion';

The following methods and properties are accessible:

Entry Point Type Usage
schema(data) Method Ensures that the passed in schema is in the vunion reactive state.

This should be called when you are defining a store.

The "data" property is an object that contains the properties to map into the reactive state with their default values.

If the property already exists in the state then it leaves the current value as is. If it does not exist it adds it and sets it's value to the default.

get(name) Method Gets the value of a property in the vunion reactive state.

The "name" parameter is the string name of the property you wish to return.

If you are using structured objects in your state then you will need the full path the property you want to return using namespacing

You can use '/' or '.' characters in your namespacing, either work.

commit(name, value) Method Sets the value of a property in the vunion reactive state.

The "name" parameter is the string name of the property you wish to return.

The "value" parameter is the value of the property you are trying to set. Can be any type.

For "name" the same namespacing rules apply as in the above get method.

getState() Method Returns the entire vunion state as a plain JavaScript object.
setState(state) Method Sets the entire vunion reactive state based on a plain JavaScript object.

The "state" parameter is a plan JavaScript object that will be used to map the properties and values into the state.

Any existing properties of the same name will have their values set to the passed in values.

Bus

This is the event bus module that exposes the all interactions with the event bus.

import vunion from 'vunion';
vunion.bus

Or by named export:

import {bus} from 'vunion';

Since we are utilizing the Vue event system as the backbone of the bus, it follows/mirrors the Vue Event API. All methods exposed ($emit, $on, $once, $off) are exactly the same as the Vue instance methods so it is easy to change your existing events to Bus events if you wish to.