Giter Club home page Giter Club logo

overvue's Introduction

OverVue

OverVue is a stream-based persistent state management library for Vue built on RxJS observables.

While Vuex provides a robust option for handling state in Vue applications, persistence requires third-party plugin support. The OverVue state management library includes persisted state out of the box.

OverVue leverages an RxJS Observable stream to manage synchronous and asynchronous updates to state and easily integrates with Vue applications. With OverVue, all actions are emitted to our single source of truth, the motherstream, along with any Observables contained therein. This allows users to easily assimilate Observables into their Vue applications while maintaining the Flux-based architecture most conducive to Vue.

Disclaimer

OverVue is in the early stages of development. We welcome any constructive feedback and encourage users to open issues or submit pull requests in order to contribute to the ongoing evolution of OverVue.

Getting Started

npm install --save overvue-rx

Create a central store

Creating your store is a simple two-step process with OverVue:

In your store file, import OverVue and connect it using the Vue.use() global method.

import Vue from 'vue';
import { Overvue, Store } from 'overvue-rx';

Vue.use(Overvue);

Next, in the file containing your root Vue instantiation, pass your mutate methods into createStateStream and subscribe to the store. Be sure to import the relevant files and set the store as a property in your root Vue instantiation. This makes the store accessible in all components.

import store from './store';
import mutate from './mutate';

store.createStateStream(mutate).subscribe();

const app = new Vue({
  el: '#App',
  store,
  router,
  render: h => h(Container),
});

Dispatch actions

All dispatched actions will be emitted and mapped into OverVue's motherstream. Users simply call the dispatchAction method from the store and pass in a callback function, which will return an object containing type and payload to be used as state update instructions to the user-defined mutators. The following is a simple example of how to declare an action in OverVue:

export const commitUsername = store.dispatchAction(payload => ({
  type: 'SET_USERNAME',
  payload,
}));

In this example, commitUsername can be easily imported into any file requiring it and utilized in the same way one would use actions in any Flux-based state management library.

Commit mutations

As in other Flux-based state management libraries, state is never directly effected by dispatched actions. Rather, actions commit mutators which mutate state and save the new state object in session storage, allowing it to persist through page reloads. This allows actions to perform complex asynchronous tasks without the risk of state being inappropriately changed.

This is an example of how a committed mutate method will handle a dispatched action:

export default function mutate(state, action) {
  switch (action.type) {
    case 'SET_USERNAME':
      state.username = action.payload.username;
      return state;
};

And that's it!

overvue's People

Contributors

dropkode21 avatar hit1st avatar jgmcalpine avatar smozingo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.