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

@tingyuan/vue-store

v0.0.15

Published

simpler vuex alternative

Downloads

18

Readme

vue-store

still developing...

npm version

a simpler way to use redux-like state management in vue project

  • Simpler way to share and change your application state, NO ACTION_TYPE, commit, dispatch, helpers...
  • Better and natural support for typescript
  • Small size but with adequate support

install

npm install @tingyuan/vue-store

or

<script src="https://cdn.jsdelivr.net/npm/@tingyuan/vue-store">
/* export "VueStore" as global name. */
</script>

example

store.ts

type Item = { text: string, done: boolean }

const todoModule = {
  list: [] as Item[],
  get doneCount() {
    return this.list.filter(v => v.done).length
  },
  setList(list: Item[]) {
    this.list = list
  },
  addItem(text: string) {
    this.list.push({
      text, done: false
    })
  },
  async $fetchList() {
    const list = await request('/api/get-list')
    this.setList(list)
  }
}

const modules = {
  user: {
    name: 'nobody'
  },
  setUserName(username: string) {
    this.user.name = username
  },
  Todo: todoModule
}

import Vue from 'vue'
import VueStore from '@tingyuan/vue-store'

Vue.use(VueStore)

const store = VueStore.createStore(modules, {
  strict: true,
  plugins: [
    store => {
      store.subscribe(({ type, actionType, payload }, state) => {
        if (type) {
          console.log('mutation called: ' + type)
        } else {
          console.log('action called: ' + actionType)
        }
      })
    }
  ]
})

export default store
<template>
  <div>
    <h1>Hello {{$store.user.name}}, Todo List({{counter}})</h1>
    <input type="text" placeholder="enter whatever" v-model.trim="newItem" @keyup.enter="onAdd">
    <ol>
      <li v-for="item in todoList" :key="item.id" :class="item.done ? 'done' : ''">{{item.text}}</li>
    </ol>
  </div>
</template>
<script>
export default {
  data() {
    return { newItem: '' }
  },
  computed: {
    todoList() { return this.$store.Todo.list },
    counter() { return this.$store.Todo.doneCount + '/' + this.todoList.length }
  },
  methods: {
    onAdd() {
      this.newItem && this.$store.Todo.addItem(this.newItem)
    }
  },
  created() {
    this.$store.Todo.$fetchList()
  }
}
</script>
<style>
.done { text-decoration: line-through; }
</style>

declare store option

import store from './store'
import Vue, { ComponentOptions } from 'vue'

declare module 'vue/types/options' {
  interface ComponentOptions<V extends Vue> {
    store?: typeof store
  }
}

declare module 'vue/types/vue' {
  interface Vue {
    $store: typeof store
  }
}

api

  • store = VueStore.createStore(modules, options)
  • store.watch(getter, callback)
  • store.subscribe(listener)
  • store.addModule(modulePath, module, options)
  • store.removeModule(modulePath)
  • store.replaceState(newState)
  • store.getState()
  • store.hotUpdate(path, module)

convention(compulsory in fact)

  1. name of sub-module(namespace) starts with capital letter
  2. name of action method(with side-effect) starts with '$'
  3. getter property will be taken as 'getters'