Giter Site home page Giter Site logo

vuex-utils's Introduction

Vuex Utils

Utility functions for common Vuex patterns. Creates state (or state method) and mutations

Common patterns

  • Set a property, with an initial value.
  • Reset a property to an initial value.
  • Toggle a boolean.
  • Create a model from a state+mutation.
  • combine into a state/mutations object

Specific patterns (extensions of the common patterns)

  • Loading: true/false (initially false)
  • Email set/reset.
  • Password with show/hide property

Getting started

  1. npm install vuex-utils
  2. Use to build your state

Examples

Typical login form

import {makeEmail, makeDisplayablePassword, makeErrorMessage} from 'vuex-utils/form'
import {combine} from 'vuex-utils'

const {state, mutations} = combine(
  makeEmail,
  makeDisplayablePassword,
  makeErrorMessage
)

/*
> state: {
  email: '',
  password: '',
  hidePassword: true,
  errorMessage: {}
}

> mutations: {
  setEmail: ...,
  resetEmail: ...,
  setPassword: ...,
  resetPassword: ...,
  setErrormessage: ...,
  resetErrormessage: ...,
  toggleHidepassword: ...,
  resetHidepassword: ...,
}
*/

Method that clones the state

import {combine, makeSetter} from 'vuex-utils'
import {makeLoading} from 'vuex-utils/loading'

const {state, mutations} = combineFunction(
  makeLoading,
  [makeSetter, 'amount', 0] // or makeSetter('amount', 0) with makeSetter imported from 'vuex-utils/factories'
)


/*
State is now a method that returns a clone of the state object, as Vuex expects
> state: () => {
  loading: false,
  amount: 0
}

> mutations: {
  loadingTrue: ...,
  loadingFalse: ...,
  setAmount: ...
}

*/

Changelog

  • add makeArray to handle arrays in state and basic mutations for adding, removing and clearing array (mutating)
  • new collaborator, thank you @clive07

vuex-utils's People

Contributors

matiboy avatar clive107 avatar

Watchers

James Cloos avatar Yu Jin Lim 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.