2.4.91 • Published 1 year ago

vuelpers v2.4.91

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

vuelpers

Extented vue helpers functions

Install

$ npm install vuelpers

or with yarn

$ yarn add vuelpers

Functions

1. createMutations

It's a vuex mutations generator which we use commonly to make changes in state like set a state value, push, update, delete a item in an array, reset the whole state. Using this package you don't have to write any mutations to make changes in state it has all the neccessary mutations to update state.

import { createMutations } from 'vuelpers'

const initialState = () => ({
  loading: false,
  counter: 0,
  user: {
    name: null
  }
})

const mutations = {
  ...createMutations('SET')
  // your other mutations
}
  commit('SET', { loading: true })
  commit('SET', { counter: c => c + 1 })
  commit('SET', { 'user.name': 'John Doe' })

or in single object

  commit('SET', { 
    loading: true,
    counter: c => c + 1,
    'user.name': 'John Doe'
  })

Mutations Types

There is the list of mutation types

SET - Set or change something to the state.\ RESET - Reset the current state to initial state.\ PUSH - Push items in an array.\ UNSHIFT - Unshift items in an array.\ UPDATE - Replace an array item with specified item.\ DELETE - Delete an array item with specified id or any identifier.

Lets breakdown each of these. Consider this is our store.

import { createMutations } from 'vuelpers'

const initialState = () => ({
  users: {
    page: 1,
    perPage: 20,
    data: [
      {
        id: 1,
        name: 'John doe',
        email: 'john@gmail.com'
      },
      {
        id: 2,
        name: 'David Davis',
        email: null
      }
    ],
  },
  books: [
    {
      id: 1,
      name: 'Book Name'
    }
  ]
})
const mutations = {
  ...createMutations('SET', 'RESET', 'PUSH', 'UNSHIFT', 'UPDATE', 'DELETE')
  // your other mutations
}

RESET

commit('RESET', initialState())

PUSH and UNSHIFT

let newUser = {
  id: 3,
  name: 'Thomas Rivers',
  email: 'thomas@gmail.com'
}

commit('PUSH', ['users.data', newUser])

// or like this
commit('PUSH', {
  'user.data': newUser
})

// or multiple item at once
commit('PUSH', {
  'user.data': [newUser, anotherUser]
})

// or (push or unshift) to multiple array at once
commit('PUSH', {
  'books': newBook,
  'user.data': [newUser, anotherUser],
})

UPDATE

commit('UPDATE', ['users.data', newUser, /* id - optional parameter to match by */])
MethodsReturnsDescriptions
isEmpty(value:any)booleanCheck if the given value is empty or not
miniId(len?: number)stringGenerate a random id of maximum 10 characters length
sleep(time?:number, unit?: string)Promise<any>Promise to await specific time
2.4.91

1 year ago

2.4.9

1 year ago

2.4.8

1 year ago

2.4.7

2 years ago

2.4.3

2 years ago

2.4.5

2 years ago

2.4.4

2 years ago

2.4.6

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.4.2

2 years ago

2.3.8

2 years ago

2.3.9

2 years ago

2.3.7

2 years ago

2.2.7

2 years ago

2.3.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.3.4

2 years ago

2.3.3

2 years ago

2.3.6

2 years ago

2.3.5

2 years ago

2.2.9

2 years ago

2.2.8

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.6

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

2.2.1

2 years ago

2.1.2

2 years ago

2.0.3

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.0.2

2 years ago

2.2.3

2 years ago

2.1.4

2 years ago

2.0.5

2 years ago

2.2.2

2 years ago

2.1.3

2 years ago

2.0.4

2 years ago

2.1.6

2 years ago

2.0.7

2 years ago

2.1.5

2 years ago

2.0.6

2 years ago

2.1.8

2 years ago

2.0.9

2 years ago

2.1.7

2 years ago

2.0.8

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.1.9

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago