Socket
Socket
Sign inDemoInstall

pinia-dx

Package Overview
Dependencies
25
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pinia-dx

Pinia DX improvement experiment (Composition API Only).


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

pinia-dx

Pinia DX improvement experiment (Composition API Only).

This is a very simple wrapper of pinia to try difference API.

import { reactive, toRefs } from 'vue'
- import { defineStore } from 'pinia'
+ import { defineStore } from 'pinia-dx'

- export const useUserStore = defineStore('user', () => {
+ export const userStore = defineStore(() => {

	const state = reactive({
		name: 'Eduardo',
		/** @type {boolean} */
		isAdmin: true,
	})

	return {
		...toRefs(state),
		login,
		logout
	}

	async function login(user, password) {
		// ...
	}
	function logout() {
		// ...
	}
})

In this API, defineStore is not support for SSR, if use SSR, you need to use defineSSRStore('user', () => ...) for replacement.

<script setup>
- import { useUserStore } from './stores/user'
+ import { userStore } from './stores/user'

- const user = useUserStore()

// ...

await user.login('user', 'password')
console.log(user.name, user.isAdmin)
</script>

Example code modify from https://codesandbox.io/s/github/posva/pinia-vue-3-demo-codesandbox

FAQs

Last updated on 26 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc