Socket
Socket
Sign inDemoInstall

little-state-machine

Package Overview
Dependencies
Maintainers
1
Versions
210
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

little-state-machine - npm Package Compare versions

Comparing version 4.0.0-rc.1 to 4.0.0-rc.2

dist/little-state-machine.es.js

6

dist/index.d.ts

@@ -1,2 +0,4 @@

import { createStore, StateMachineProvider, useStateMachine } from './stateMachine';
export { createStore, StateMachineProvider, useStateMachine };
import { StateMachineProvider } from './StateMachineContext';
import { createStore, useStateMachine } from './stateMachine';
import { GlobalState } from './types';
export { createStore, StateMachineProvider, useStateMachine, GlobalState };

@@ -1,1 +0,2 @@

export declare function setUpDevTools<T>(storageType: Storage, name: string, store: T): void;
import { GlobalState } from "../types";
export declare function setUpDevTools(storageType: Storage, name: string, state: GlobalState): void;

@@ -1,10 +0,12 @@

import { MiddleWare } from '../types';
export default class StoreFactory {
import { MiddleWare, GlobalState } from '../types';
declare class StoreFactory {
name: string;
storageType: Storage;
store: unknown;
state: GlobalState;
middleWares: MiddleWare[];
constructor(name: string, isClient: boolean);
updateStore<T>(defaultValues: T): void;
constructor(name?: string);
updateStore(defaultValues: GlobalState): void;
updateMiddleWares(middleWares: MiddleWare[]): MiddleWare[];
}
declare const _default: StoreFactory;
export default _default;

@@ -1,8 +0,6 @@

/// <reference types="react" />
import { StateMachineOptions, ActionsArg, Actions } from './types';
export declare function createStore<T>(defaultStoreData: T, options?: StateMachineOptions): void;
export declare function StateMachineProvider<T>(props: T): JSX.Element;
export declare function useStateMachine<T, TActions extends ActionsArg<T> = ActionsArg<T>>(actions?: TActions): {
actions: Actions<T, TActions>;
state: T;
import { StateMachineOptions, GlobalState, AnyCallback, AnyActions, ActionsOutput } from './types';
export declare function createStore(defaultState: GlobalState, options?: StateMachineOptions): void;
export declare function useStateMachine<TCallback extends AnyCallback, TActions extends AnyActions<TCallback>>(actions?: TActions): {
actions: ActionsOutput<TCallback, TActions>;
state: GlobalState;
};

@@ -1,10 +0,13 @@

export declare type Store = Record<string, any>;
export declare type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
/// <reference types="react" />
export interface GlobalState {
}
export declare type AnyCallback = (state: GlobalState, payload: any) => GlobalState;
export declare type AnyActions<TCallback> = Record<string, TCallback>;
export declare type ActionsOutput<TCallback extends AnyCallback, TActions extends AnyActions<TCallback>> = {
[K in keyof TActions]: (payload: Parameters<TActions[K]>[1]) => void;
};
export declare type StoreUpdateFunction<T> = (store: T, payload: DeepPartial<T>) => T;
export declare type Action<T> = (payload: DeepPartial<T>) => void;
export declare type Actions<T, K> = Record<keyof K, Action<T>>;
export declare type ActionArg<T> = (globalStore: T, payload: DeepPartial<T>) => T;
export declare type ActionsArg<T> = Record<string, ActionArg<T>>;
export declare type StateMachineContextValue = {
state: GlobalState;
setState: React.Dispatch<React.SetStateAction<GlobalState>>;
};
export declare type MiddleWare = <T>(arg: T) => T;

@@ -11,0 +14,0 @@ export declare type StateMachineOptions = {

@@ -8,20 +8,12 @@ {

],
"version": "4.0.0-rc.1",
"source": "src/index.ts",
"main": "dist/index.js",
"module": "dist/index.es.js",
"jsnext:main": "dist/index.esm.js",
"unpkg": "dist/index.umd.js",
"umd:main": "dist/index.umd.js",
"jsdelivr": "dist/index.umd.js",
"esmodule": "dist/index.modern.js",
"version": "4.0.0-rc.2",
"main": "dist/little-state-machine.js",
"module": "dist/little-state-machine.es.js",
"unpkg": "dist/little-state-machine.umd.js",
"types": "dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist/*",
"prebuild": "yarn clean",
"build": "microbundle build --jsx React.createElement",
"build:modern": "rollup -c ./rollup/rollup.config.js",
"build:umd": "rollup -c ./rollup/rollup.umd.config.js",
"build:min": "rollup -c ./rollup/rollup.min.config.js",
"build:ie11": "rollup -c ./rollup/rollup.ie11.config.js",
"prebuild": "rimraf dist",
"build": "npm-run-all --parallel build:*",
"build:min": "microbundle -f umd,cjs --jsx React.createElement --define process.env.NODE_ENV=production",
"build:es": "microbundle -f es --jsx React.createElement",
"release": "npm version",

@@ -31,3 +23,3 @@ "postrelease": "yarn publish && git push --follow-tags",

"test:watch": "yarn test -- --watchAll",
"prepublish": "yarn run clean && yarn build"
"prepublish": "yarn run prebuild && yarn build"
},

@@ -42,11 +34,10 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/runtime-corejs3": "^7.9.6",
"@types/react": "^16.8.8",
"jest": "24.7.1",
"microbundle": "^0.12.4",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"rimraf": "^3.0.2",
"ts-jest": "^24.0.0",

@@ -53,0 +44,0 @@ "typescript": "^4.0.0"

@@ -17,3 +17,3 @@ <div align="center"><a href="https://lrz5wloklm.csb.app/"><img src="https://github.com/bluebill1049/little-state-machine/blob/master/docs/logo.png?raw=true" alt="Little State Machine - React Hooks for state management" width="140px" /></a>

- Tiny with 0 dependency and simple (699B)
- Tiny with 0 dependency and simple (639B _gzip_)
- Persist state by default (`sessionStorage` or `localStorage`)

@@ -72,3 +72,3 @@ - Build with React Hooks

Quick video tutorial on little state machine.
Quick video tutorial on little state machine.

@@ -79,3 +79,2 @@ <a href="https://scrimba.com/scrim/ceqRebca">

<h2>📖 Example</h2>

@@ -87,3 +86,7 @@

import React from 'react';
import { StateMachineProvider, createStore, useStateMachine } from 'little-state-machine';
import {
StateMachineProvider,
createStore,
useStateMachine,
} from 'little-state-machine';

@@ -121,2 +124,56 @@ createStore({

## ⌨️ Type Safety (TS)
You can create a `global.d.ts` file to declare your GlobalState's type.
```ts
declare module 'little-state-machine' {
interface GlobalState {
yourDetail: {
name: string;
};
}
}
```
```tsx
import * as React from 'react';
import {
createStore,
useStateMachine,
StateMachineProvider,
GlobalState,
} from 'little-state-machine';
createStore({
yourDetail: { name: '' },
});
const updateName = (state: GlobalState, payload: { name: string }) => ({
...state,
yourDetail: {
...state.yourDetail,
...payload,
},
});
const YourComponent = () => {
const { actions, state } = useStateMachine({
updateName
}));
return (
<div onClick={() => actions.updateName({ name: 'Kotaro' })}>
{state.yourDetail.name}
</div>
);
};
const App = () => (
<StateMachineProvider>
<YourComponent />
</StateMachineProvider>
);
```
<h2>⚒ DevTool</h2>

@@ -135,10 +192,6 @@

<h2>🖥 Browser Compatibility</h2>
Little State Machine supports all major browsers
Little State Machine supports all major browsers IE11 include !
For legacy IE11 support, you can import little-state-machine IE11 version.
If you run into issues, feel free to open an [issue](https://github.com/bluebill1049/little-state-machine/issues).
```tsx
import { createStore } from 'little-state-machine/dist/little-state-machine.ie11';
```
<h2>📋 Polyfill</h2>

@@ -145,0 +198,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc