npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@inventistudio/vuex-mutations

v1.0.1

Published

Factory of vuex mutations. DRY.

Downloads

3

Readme

vuex-mutations, by InventiStudio

Factory of vuex mutations. DRY.

Table of Contents

Install

# npm
npm i --save @inventistudio/vuex-mutations
# or yarn
yarn add @inventistudio/vuex-mutations

Example

import Mutations from '@inventistudio/vuex-mutations'

const state = {
  // Prepare state
  me: {
    login: '',
    email: '',
  },
  comments: [],
}

const mutations = {
  // Magic
  SET_USER:          Mutations.set('me'),
  UPDATE_USER_EMAIL: Mutations.set('me.email'),
  ADD_COMMENT:       Mutations.add('comments'),
  UPDATE_COMMENT:    Mutations.update('comments', { matchBy: 'comment_id' }),
  REMOVE_COMMENT:    Mutations.remove('comments', { matchBy: 'comment_id' }),
  ADD_FULL_COMMENT:  Mutations.addOrUpdate('comments', { matchBy: 'comment_id' })
}

const actions = {
  // Do your stuff here. Use mutations.
  SET_USER_ACTION({ commit }, user) {
    commit('SET_USER', user)
  }
  // (...)
}

API

Mutations

Collection of functions that create mutations

Mutations.add(path, options) ⇒ Mutation(state, element)

It creates mutation that adds element to array

Kind: static method of Mutations

| Param | Type | Default | Description | | --- | --- | --- | --- | | path | String | | Path to array | | options | Object | | | | [options.position] | String | 'first' | Determine if element should be inserted at the beginning ('first') or end ('last') |

Example

const mutations = {
  ADD_USER:        add('users'),
  ADD_USER_AT_END: add('users', { position: 'last' }),
}

Mutations.update(path, options) ⇒ Mutation(state, element)

It creates mutation that updates element of array. It does nothing if not found

Kind: static method of Mutations

| Param | Type | Default | Description | | --- | --- | --- | --- | | path | String | | Path to array | | options | Object | | | | [options.matchBy] | function | String | (a, b) => a === b | It can by function or propery name |

Example

const mutations = {
  UPDATE_BY_REFERENCE:   update('path.to.array'),
  UPDATE_BY_ID:          update('path.to.array', { matchBy: 'id' }),
  UPDATE_BY_CUSTOM_FUNC: update('path.to.array', { matchBy(a, b) { return a.name === b.name } }),
}

Mutations.addOrUpdate(path, options) ⇒ Mutation(state, element)

It creates mutation that updates element of array if found. It adds it if not.

Kind: static method of Mutations

| Param | Type | Default | Description | | --- | --- | --- | --- | | path | String | | Path to array | | options | Object | | | | [options.position] | String | 'first' | Determine if element should be inserted at the beginning ('first') or end ('last') | | [options.matchBy] | function | String | (a, b) => a === b | It can by function or propery name |

Example

const mutations = {
  UPDATE_OR_ADD_BY_REFERENCE:   addOrUpdate('path.to.array'),
  UPDATE_OR_ADD_BY_ID:          addOrUpdate('path.to.array', { matchBy: 'data.id', position: 'last' }),
  UPDATE_OR_ADD_BY_CUSTOM_FUNC: addOrUpdate('path.to.array', { matchBy(a, b) { return a.name === b.name } }),
}

Mutations.remove(path, options) ⇒ Mutation(state, element)

It creates mutation that removes element from array. It does nothing if not found

Kind: static method of Mutations

| Param | Type | Default | Description | | --- | --- | --- | --- | | path | String | | Path to array | | options | Object | | | | [options.matchBy] | function | String | (a, b) => a === b | It can by function or propery name |

Example

const mutations = {
  REMOVE_BY_REFERENCE:   remove('path.to.array'),
  REMOVE_BY_ID:          remove('path.to.array', { matchBy: 'id' }),
  REMOVE_BY_CUSTOM_FUNC: remove('path.to.array', { matchBy(a, b) { return a.name === b.name } }),
}

Mutations.set(path) ⇒ Mutation(state, element)

It creates mutation that sets object property.

Kind: static method of Mutations

| Param | Type | Description | | --- | --- | --- | | path | String | Path to property |

Example

const mutations = {
  SET_SOMETHING: set('path.to.prop'),
}