New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

justorm

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

justorm

Just store manager.

latest
Source
npmnpm
Version
3.0.2
Version published
Weekly downloads
81
-23.58%
Maintainers
1
Weekly downloads
 
Created
Source

npm

Just Store Manager

Simple state/store manager based on Proxy.

API

  • createStore(name, object) – creates new store with provided name

  • useStore(config: string | object | array ) – subscribe component to store

    • useStore({ user: ['firstName'] }) – to field firstName of store user

    • useStore({ user: true }) – to all fields of store user

    • useStore('user') – to all fields of stores user

    • useStore(['user', 'auth']) - to all fields of stores user and auth

    • useStore(['user', { auth: ['isAuthorized'] }])

      • to all fields of stores user
      • and field isAuthorized of store auth
  • connect(storeName: string, fields: string[], callback: () => void) – subscribe callback to store.

  • disconnect(storeName: string, fields: string[], callback: () => void) – unsubscribe callback to store.

  • store.originalObject – returns original object (without Proxy wrapper)

Import

import { createStore, connect, disconnect } from 'justorm'; // for VanillaJS
// or
import { createStore, useStore } from 'justorm/react'; // for React
// or
import { createStore, useStore } from 'justorm/preact'; // for Preact

NOTE: You don't need to unsubscribe from store when using decorator useStore. useStore do it for you.

Create store

Describe store and actions in one place. Demo.

createStore('user', {
  isLogged: false,
  login() {
    this.isLogged = true;
  },
  logout() {
    this.isLogged = false;
  },
});

function App() {
  const { isLogged, login, logout } = useStore({ user: ['isLogged'] });

  const onClick = isLogged ? logout : login;
  const text = isLogged ? 'logout' : 'login';

  return <button onClick={onClick}>{text}</button>;
});

Vanilla JS

Demo.

import { createStore, connect, disconnect } from 'justorm';

const myStore = createStore('my-store', {
  isLogged: false;
  user: null
});

function onLoggedChange() {
  console.log(myStore.isLogged ? 'Welcome!' : 'See ya!');
}
function onAnyFieldChange() {
  console.log('Some field changed:', myStore);
}

connect('my-store', ['isLogged'], onLoggedChange);
connect('my-store', onAnyFieldChange);

myStore.isLogged = true;
// Welcome!
// Some field changed: { isloggeg: true, user: null }
console.log('-----------');

myStore.user = 'Jess';
// Some field changed: { isloggeg: true, user: 'Jess' }
console.log('-----------');

Object.assign(myStore, { isLogged: false, user: null });
// See ya!
// Some field changed: { isLogged: false, user: null }
// Some field changed: { isLogged: false, user: null }

disconnect('my-store', onLoggedChange);
disconnect('my-store', onAnyFieldChange);

Keywords

store

FAQs

Package last updated on 14 Jun 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