Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@snap/state-management

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@snap/state-management - npm Package Compare versions

Comparing version 0.17.0 to 0.18.0

18

dist/actions.d.ts

@@ -1,3 +0,3 @@

import { OperatorFunction } from 'rxjs';
import { IfEmpty, Named } from './types';
import type { OperatorFunction } from "rxjs";
import type { IfEmpty, Named } from "./types";
type ActionCreators<Actions extends readonly Action[]> = {

@@ -7,3 +7,3 @@ readonly [K in keyof Actions]: ActionCreator<Actions[K]>;

export type ActionCreatorMap<T extends readonly Action[]> = {
[Name in T[number]['name']]: ActionCreator<Named<T[number], Name>>;
[Name in T[number]["name"]]: ActionCreator<Named<T[number], Name>>;
};

@@ -14,8 +14,8 @@ export interface Action<Name extends string = string, Data = any> {

}
export type ActionCreator<A extends Action> = IfEmpty<A['data'], {
export type ActionCreator<A extends Action> = IfEmpty<A["data"], {
(): A;
name: A['name'];
name: A["name"];
}, {
(data: A['data']): A;
name: A['name'];
(data: A["data"]): A;
name: A["name"];
}>;

@@ -56,3 +56,3 @@ /**

*/
export declare function forActions<A extends Action, Names extends A['name'][], S>(...actions: Names): OperatorFunction<[A, S], [Named<A, Names[number]>, S]>;
export declare function forActions<A extends Action, Names extends A["name"][], S>(...actions: Names): OperatorFunction<[A, S], [Named<A, Names[number]>, S]>;
/**

@@ -65,3 +65,3 @@ * Determine if a given action is of a specific type, given by an action name. This narrows the type of the action.

*/
export declare function isAction<A extends Action, Name extends A['name']>(action: A, name: Name): action is Named<A, Name>;
export declare function isAction<A extends Action, Name extends A["name"]>(action: A, name: Name): action is Named<A, Name>;
export {};

@@ -1,3 +0,3 @@

import { filter } from 'rxjs';
import { fromEntries } from './types';
import { filter } from "rxjs";
import { fromEntries } from "./types";
/**

@@ -16,3 +16,3 @@ * Define an Action by providing a name and (optionally) the type of data the Action carries. Returns a function which

});
Object.defineProperty(actionCreator, 'name', { value: name });
Object.defineProperty(actionCreator, "name", { value: name });
// Safety: Object.defineProperty has added the `name` property, but the TS compiler doesn't know that.

@@ -47,3 +47,3 @@ return actionCreator;

export function forActions(...actions) {
return filter((v) => actions.some(action => v[0].name === action));
return filter((v) => actions.some((action) => v[0].name === action));
}

@@ -50,0 +50,0 @@ /**

@@ -1,3 +0,3 @@

export * from './actions';
export * from './state-machine';
export * from './states';
export * from "./actions";
export * from "./state-machine";
export * from "./states";

@@ -1,3 +0,3 @@

export * from './actions';
export * from './state-machine';
export * from './states';
export * from "./actions";
export * from "./state-machine";
export * from "./states";

@@ -1,5 +0,6 @@

import { Observable, OperatorFunction } from 'rxjs';
import { Action, ActionCreatorMap } from './actions';
import { State, StateCreatorMap } from './states';
import { Named } from './types';
import type { OperatorFunction } from "rxjs";
import { Observable } from "rxjs";
import type { Action, ActionCreatorMap } from "./actions";
import type { State, StateCreatorMap } from "./states";
import type { Named } from "./types";
export type Actions<M extends StateMachine<any, any>> = M extends StateMachine<infer Actions, any> ? Actions : never;

@@ -119,3 +120,3 @@ export type States<M extends StateMachine<any, any>> = M extends StateMachine<any, infer States> ? States : never;

*/
dispatch<Name extends Actions['name']>(name: Name, data: Named<Actions, Name>['data']): void;
dispatch<Name extends Actions["name"]>(name: Name, data: Named<Actions, Name>["data"]): void;
/**

@@ -122,0 +123,0 @@ * Returns the current state.

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

import { BehaviorSubject, map, mergeMap, NEVER, Observable, of, raceWith, startWith, Subject, take, tap, withLatestFrom } from 'rxjs';
import { BehaviorSubject, map, mergeMap, NEVER, Observable, of, raceWith, startWith, Subject, take, tap, withLatestFrom, } from "rxjs";
/**

@@ -126,3 +126,3 @@ * A StateMachine takes a finite set of both Action and State types, representing the allowed states of the machine and

dispatch(actionOrName, data) {
const action = typeof actionOrName === 'string' ? { name: actionOrName, data } : actionOrName;
const action = typeof actionOrName === "string" ? { name: actionOrName, data } : actionOrName;
this.actionsSubject.next(action);

@@ -154,3 +154,3 @@ }

export function dispatch(stateMachine) {
return (source) => new Observable(subscriber => {
return (source) => new Observable((subscriber) => {
const subscription = stateMachine.events.subscribe(subscriber);

@@ -160,4 +160,5 @@ subscription.add(source.subscribe({

error: (error) => subscriber.error(error),
// We purposely do not forward the `complete` notification. We want the subscriber to remain subscribed to
// the stateMachine.events observable even if the source Observable<Actions> completes.
// We purposely do not forward the `complete` notification.
// We want the subscriber to remain subscribed to the stateMachine.events observable even if the
// source Observable<Actions> completes.
}));

@@ -164,0 +165,0 @@ return subscription;

@@ -1,5 +0,5 @@

import { OperatorFunction } from 'rxjs';
import { IfEmpty, Named } from './types';
import type { OperatorFunction } from "rxjs";
import type { IfEmpty, Named } from "./types";
export type StateCreatorMap<T extends readonly State[]> = {
[Name in T[number]['name']]: StateCreator<Named<T[number], Name>>;
[Name in T[number]["name"]]: StateCreator<Named<T[number], Name>>;
};

@@ -13,8 +13,8 @@ export type StateCreators<States extends readonly State[]> = {

}
export type StateCreator<S extends State> = IfEmpty<S['data'], {
export type StateCreator<S extends State> = IfEmpty<S["data"], {
(): S;
name: S['name'];
name: S["name"];
}, {
(data: S['data']): S;
name: S['name'];
(data: S["data"]): S;
name: S["name"];
}>;

@@ -55,3 +55,3 @@ /**

*/
export declare function inStates<S extends State, Names extends S['name'][], A>(...states: Names): OperatorFunction<[A, S], [A, Named<S, Names[number]>]>;
export declare function inStates<S extends State, Names extends S["name"][], A>(...states: Names): OperatorFunction<[A, S], [A, Named<S, Names[number]>]>;
/**

@@ -64,2 +64,2 @@ * Determine if a given state is of a specific type, given by an state name. This narrows the type of the state.

*/
export declare function isState<S extends State, Name extends S['name']>(state: S, name: Name): state is Named<S, Name>;
export declare function isState<S extends State, Name extends S["name"]>(state: S, name: Name): state is Named<S, Name>;

@@ -1,3 +0,3 @@

import { filter } from 'rxjs';
import { defineAction, defineActions } from './actions';
import { filter } from "rxjs";
import { defineAction, defineActions } from "./actions";
/**

@@ -32,3 +32,3 @@ * Define a State by providing a name and (optionally) the type of data the State carries. Returns a function which

export function inStates(...states) {
return filter((v) => states.some(state => v[1].name === state));
return filter((v) => states.some((state) => v[1].name === state));
}

@@ -35,0 +35,0 @@ /**

{
"name": "@snap/state-management",
"version": "0.17.0",
"version": "0.18.0",
"license": "SEE LICENSE IN LICENSE.md",

@@ -13,3 +13,5 @@ "description": "Redux-inspired state management using Observables",

"files": [
"dist"
"dist",
"!**/__tests__",
"!**/__mocks__"
],

@@ -24,2 +26,3 @@ "peerDependencies": {

"eslint": "8.40.0",
"eslint-plugin-comment-length": "^1.7.3",
"jest": "29.5.0",

@@ -26,0 +29,0 @@ "ts-jest": "29.1.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