Git Product home page Git Product logo

vue-simple-state-management's Introduction

Vue-simple-state-management

Simple state management in Vue with provide/inject plus a Vue instance as event emitter

Installation

npm install

Then:

npm serve

To open a local dev server in the 8080 port. This project is built with vue-cli 3 so all the vue cli standard commands are available.

Why this

Sometimes, a vuex store to manage the state of a small application or a related group of components is some sort of an overkill (or so they say).

If you're not using a store, you will need to re-emit a lot of events and pass a lot of props down to long chains of components, which feels awkward and usually forces you to not split your application in components enough.

A way to handle this situation in React is the context api. Vue has a similar feature, provide/inject. Just providing a state object with provide solves the prop drilling problem, but provide/inject itself doesn't help to avoid the events re-emitting.

A way to avoid constant event re-emitting is to provide a Vue instance that serves as an event emitter (and, in fact, an EventEmitter instance will work the same). Instead of emitting and listening to events using $emit and $on on the components, we emit and listen events from and to a provided Vue instance.

vue-simple-state-management's People

Contributors

sergeon avatar

Stargazers

César Alberca avatar

Watchers

James Cloos 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.