Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@kalxjs/store

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kalxjs/store

Global state management for KalxJS framework

latest
Source
npmnpm
Version
1.0.10
Version published
Maintainers
1
Created
Source

@kalxjs/store

Global state management for KalxJS applications

This package provides a state management solution for KalxJS applications.

Installation

npm install @kalxjs/store

Usage

import { createApp } from '@kalxjs/core';
import { createStore } from '@kalxjs/store';
import App from './App.js';

// Create a store
const store = createStore({
  state: {
    count: 0
  },
  mutations: {
    increment(state) {
      state.count++;
    },
    decrement(state) {
      state.count--;
    }
  },
  actions: {
    incrementAsync({ commit }) {
      setTimeout(() => {
        commit('increment');
      }, 1000);
    }
  }
});

// Create app and use store
const app = createApp(App);
app.use(store);
app.mount('#app');

In your components:

import { mapState } from '@kalxjs/store';

export default {
  computed: {
    ...mapState(['count'])
  },
  methods: {
    increment() {
      this.$store.commit('increment');
    },
    decrement() {
      this.$store.commit('decrement');
    },
    incrementAsync() {
      this.$store.dispatch('incrementAsync');
    }
  }
};

API

createStore(options)

Creates a new store instance.

Options:

  • state: The root state object
  • mutations: Methods to mutate the state
  • actions: Methods to perform async operations and commit mutations
  • getters: Computed properties for the store

mapState(namespace?, map)

Maps store state to component computed properties.

mapGetters(namespace?, map)

Maps store getters to component computed properties.

mapMutations(namespace?, map)

Maps store mutations to component methods.

mapActions(namespace?, map)

Maps store actions to component methods.

License

MIT

FAQs

Package last updated on 17 May 2025

Did you know?

Socket

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