All Projects → nanostores → vue

nanostores / vue

Licence: MIT license
Vue integration for Nano Stores, a tiny state manager with many atomic tree-shakable stores

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to vue

teaful
🍵 Tiny, easy and powerful React state management
Stars: ✭ 638 (+2452%)
Mutual labels:  state-management, state, store
okito
Your best flutter coding friend. All in one; state management, navigation management(with dynamic routing), local storage, localization, dependency injection, cool extensions with best usages and with the support of best utilities!
Stars: ✭ 37 (+48%)
Mutual labels:  state-management, state, store
vue-unstated
A tiny state management library for Vue Composition API.
Stars: ✭ 30 (+20%)
Mutual labels:  state-management, store, vue3
Vue State Store
📮 VSS (Vue State Store) - Vue State Management (with Publish & Subscribe pattern)
Stars: ✭ 128 (+412%)
Mutual labels:  state-management, state, store
Westore
更好的小程序项目架构
Stars: ✭ 3,897 (+15488%)
Mutual labels:  state-management, state, store
RxReduxK
Micro-framework for Redux implemented in Kotlin
Stars: ✭ 65 (+160%)
Mutual labels:  state-management, state, store
vue-reactive-store
A VueX alternative : declarative + reactive + centralized way to structure your data store. Inspired by VueX and Vue.js . Compatible with vue-devtools.
Stars: ✭ 27 (+8%)
Mutual labels:  state-management, state, store
knockout-store
State management for Knockout apps.
Stars: ✭ 37 (+48%)
Mutual labels:  state-management, state, store
Reatom
State manager with a focus of all needs
Stars: ✭ 567 (+2168%)
Mutual labels:  state-management, state, store
vuse-rx
Vue 3 + rxjs = ❤
Stars: ✭ 52 (+108%)
Mutual labels:  state-management, state, vue3
snap-state
State management in a snap 👌
Stars: ✭ 23 (-8%)
Mutual labels:  state-management, state
query-param-store
Angular Reactive Query Parameters Store
Stars: ✭ 15 (-40%)
Mutual labels:  state-management, store
XUI
XUI makes modular, testable architectures for SwiftUI apps a breeze!
Stars: ✭ 100 (+300%)
Mutual labels:  state-management, state
atomic-state
Atomic State is a state management library for React
Stars: ✭ 15 (-40%)
Mutual labels:  state-management, state
mafuba
Simple state container for react apps.
Stars: ✭ 20 (-20%)
Mutual labels:  state, store
rex-state
Convert hooks into shared states between React components
Stars: ✭ 32 (+28%)
Mutual labels:  state-management, state
boutique
Immutable data storage
Stars: ✭ 44 (+76%)
Mutual labels:  state, store
storken
🦩 Storken is a React State Manager. Simple as `useState`.
Stars: ✭ 22 (-12%)
Mutual labels:  state-management, state
temperjs
State management for React, made simple.
Stars: ✭ 15 (-40%)
Mutual labels:  state-management, state
ReduxSimple
Simple Stupid Redux Store using Reactive Extensions
Stars: ✭ 119 (+376%)
Mutual labels:  state-management, state

Nano Stores Vue

Vue integration for Nano Stores, a tiny state manager with many atomic tree-shakable stores.

  • Small. Less than 1 KB with all helpers. Zero dependencies.
  • Fast. With small atomic and derived stores, you do not need to call the selector function for all components on every store change.
  • Tree Shakable. The chunk contains only stores used by components in the chunk.
  • Helpers. Designed to keep code clean and save a few keystrokes.
  • Devtools. Plugin with full support of Vue Devtools.
  • Was designed to move logic from components to stores.
  • It has good TypeScript support.

Install

npm install @nanostores/vue

Usage

Store state

Subscribe to store changes and use reactive store state.

<template>
  <header>{{ post.title }} for {{ user.name }}</header>
</template>

<script>
  import { useStore } from '@nanostores/vue'
  import { profile } from '../stores/profile.js'
  import { Post } from '../stores/post.js'

  export default {
    setup (props) {
      const user = useStore(profile)
      const post = useStore(Post(props.postId))
      return { user, post }
    }
  }
</script>

Multiple store states

Generate multiple store states and save a few keystrokes.

<template>
  <header>{{ project.name }} / {{ user.name }}</header>
</template>

<script>
  import { mapStores } from '@nanostores/vue'
  import { project } from '../stores/project.js'
  import { user } from '../stores/user.js'

  export default {
    setup () {
      return {
        ...mapStores({ project, user })
      }
    }
  }
</script>

Form handling

Since the store state is deep read-only, you cannot directly mutate it. But for v-model you can create model via useVModel(store, keys, opts). It will explicitly mutate the store via store.set() / store.setKey().

<template>
  <input v-model="username"/>
</template>

<script>
  import { useVModel } from '@nanostores/vue'
  import { profile } from '../stores/profile.js'

  export default {
    setup () {
      const username = useVModel(profile, 'username')
      return { username }
    }
  }
</script>

The keys argument can be an array of keys to create multiple models. Each model will be prefixed with Model. You can change it via opts.prefix.

<template>
  <input v-model="firstNameModel"/>
  <input v-model="lastNameModel"/>
</template>

<script>
  import { useVModel } from '@nanostores/vue'
  import { profile } from '../stores/profile.js'

  export default {
    setup () {
      return {
        ...useVModel(profile, ['firstName', 'lastName'])
      }
    }
  }
</script>

Devtools

Nanostores Vue Devtools screenshot

Install

npm install --save-dev @vue/devtools-api

Usage

Store detector

Install Vue Devtools plugin as usual. It will detect nanostores in selected component and add their states to the component inspector.

import { createApp } from 'vue'
import { devtools } from '@nanostores/vue/devtools'

import { User } from '../stores/user.js'

const app = createApp()
app.use(devtools)

Notice: if you are using SSR, there is no Vue Devtools on server. Check it’s a browser environment:

if (window) app.use(devtools)

Attach stores to add them to the nanostores inspector and see their builds, lifecycles and changes on the timeline.

import { createApp } from 'vue'
import { devtools, attachStores } from '@nanostores/vue/devtools'

import { User } from '../stores/user.js'

const app = createApp()
app.use(devtools)

attachStores(app, { User })

You can connect several stores in different places of your application and set custom names to simplify the work with devtools.

attachStores(app, {
  'Current User': User,
  Post
})

For MapTemplate you can create a custom nameGetter to set suitable names for each store built from template.

attachStores(app, { User }, {
  nameGetter: (store, templateName) => {
    return `User:${store.get().id}`
  }
})

Settings

The states of all detected stores in component inspector are updated in real time. You can disable this in the the plugin settings via the Real-time update detected property.

By default, we removes unmounted stores from nanostores inspector to keep it clean. You can change this via the Keep unmounted property.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].