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

storeon

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storeon - npm Package Compare versions

Comparing version 3.0.3 to 3.0.4

3

CHANGELOG.md
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 3.0.4
* Fixed types for `undefined` state (by @majo44).
## 3.0.3

@@ -5,0 +8,0 @@ * Fix TypeScript definitions (by @irustm).

2

devtools/index.d.ts

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

import { StoreonStore, StoreonModule } from '..'
import { StoreonStore, StoreonModule } from '../index.js'

@@ -3,0 +3,0 @@ export const storeonDevtools: {

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

type DataTypes<Map, Key extends keyof Map> =
Map extends never
? [any?]
: (Map[Key] extends (never | undefined) ? [never?] : [Map[Key]])
type DataTypes<Map, Key extends keyof Map> = Map extends never
? [any?]
: Map[Key] extends never | undefined
? [never?]
: [Map[Key]]

@@ -17,3 +18,3 @@ /**

*/
on <Event extends keyof (Events & StoreonEvents<State, Events>)>(
on<Event extends keyof (Events & StoreonEvents<State, Events>)>(
event: Event,

@@ -38,15 +39,14 @@ handler: createStoreon.EventHandler<State, Events, Event>

*/
dispatch: StoreonDispatch<
Events & createStoreon.DispatchableEvents<State>
>
dispatch: StoreonDispatch<Events & createStoreon.DispatchableEvents<State>>
}
export type StoreonModule<State, Events = any> =
(store: StoreonStore<State, Events>) => void
export type StoreonModule<State, Events = any> = (
store: StoreonStore<State, Events>
) => void
export interface StoreonEvents<
State, Events = any
> extends createStoreon.DispatchableEvents<State>{
export interface StoreonEvents<State, Events = any>
extends createStoreon.DispatchableEvents<State> {
'@dispatch': createStoreon.DispatchEvent<
State, Events & createStoreon.DispatchableEvents<State>
State,
Events & createStoreon.DispatchableEvents<State>
>

@@ -56,15 +56,19 @@ }

export type StoreonDispatch<Events> = (<Event extends keyof Events>(
event: Event, ...data: DataTypes<Partial<Events>, Event>
) => void) & {___events: Events}
event: Event,
...data: DataTypes<Partial<Events>, Event>
) => void) & { ___events: Events }
export namespace createStoreon {
export type DispatchEvent<
State, Events, Event extends keyof Events = keyof Events
> = [Event, Events[Event], Array<EventHandler<State, Events, Event>>]
State,
Events,
Event extends keyof Events = keyof Events
> = [Event, Events[Event], EventHandler<State, Events, Event>[]]
export type EventHandler<
State, Events, Event extends keyof (Events & StoreonEvents<State, Events>)
State,
Events,
Event extends keyof (Events & StoreonEvents<State, Events>)
> = (
state: Readonly<State>,
state: State extends object ? Readonly<State> : State,
data: (Events & StoreonEvents<State, Events>)[Event]

@@ -98,4 +102,4 @@ ) => Partial<State> | Promise<void> | null | void

*/
export function createStoreon<State, Events = any>(
modules: Array<StoreonModule<State, Events> | false>
export function createStoreon<State, Events = any> (
modules: (StoreonModule<State, Events> | false)[]
): StoreonStore<State, Events>
{
"name": "storeon",
"version": "3.0.3",
"version": "3.0.4",
"description": "Tiny (167 bytes) event-based Redux-like state manager for React and Preact",

@@ -36,3 +36,2 @@ "keywords": [

"exports": {
"./package.json": "./package.json",
".": {

@@ -42,2 +41,3 @@ "require": "./index.cjs",

},
"./package.json": "./package.json",
"./devtools/package.json": "./devtools/package.json",

@@ -44,0 +44,0 @@ "./devtools": {

@@ -8,3 +8,3 @@ import {

import { StoreonStore, StoreonDispatch } from '..'
import { StoreonStore, StoreonDispatch } from '../index.js'

@@ -34,3 +34,3 @@ declare namespace useStoreon {

*/
export function useStoreon<State extends object = {}, EventsMap = any>(
export function useStoreon<State extends object = {}, EventsMap = any> (
...keys: (keyof State)[]

@@ -76,7 +76,5 @@ ): useStoreon.StoreData<State, EventsMap>

*/
export function customContext<
State extends object = {},
EventsMap = any
>(context: Context<StoreonStore<State, EventsMap>>):
(...keys: (keyof State)[]) => useStoreon.StoreData<State, EventsMap>
export function customContext<State extends object = {}, EventsMap = any> (
context: Context<StoreonStore<State, EventsMap>>
): (...keys: (keyof State)[]) => useStoreon.StoreData<State, EventsMap>

@@ -99,3 +97,3 @@ /**

export type ConnectedComponent<ComponentProps> = FunctionalComponent<
Partial<Omit<ComponentProps, "dispatch">>
Partial<Omit<ComponentProps, 'dispatch'>>
>

@@ -119,4 +117,4 @@ }

*/
export function connectStoreon<ComponentProps>(
...keysOrComponent: Array<PropertyKey | ComponentType<ComponentProps>>
export function connectStoreon<ComponentProps> (
...keysOrComponent: (PropertyKey | ComponentType<ComponentProps>)[]
): connectStoreon.ConnectedComponent<ComponentProps>
import { Context, ComponentType, FunctionComponent } from 'react'
import { StoreonStore, StoreonDispatch } from '..'
import { StoreonStore, StoreonDispatch } from '../index.js'

@@ -28,3 +28,3 @@ export namespace useStoreon {

*/
export function useStoreon<State extends object = {}, EventsMap = any>(
export function useStoreon<State extends object = {}, EventsMap = any> (
...keys: (keyof State)[]

@@ -70,7 +70,5 @@ ): useStoreon.StoreData<State, EventsMap>

*/
export function customContext<
State extends object = {},
EventsMap = any
>(context: Context<StoreonStore<State, EventsMap>>):
(...keys: (keyof State)[]) => useStoreon.StoreData<State, EventsMap>
export function customContext<State extends object = {}, EventsMap = any> (
context: Context<StoreonStore<State, EventsMap>>
): (...keys: (keyof State)[]) => useStoreon.StoreData<State, EventsMap>

@@ -94,3 +92,3 @@ /**

export type ConnectedComponent<ComponentProps> = FunctionComponent<
Partial<Omit<ComponentProps, "dispatch">>
Partial<Omit<ComponentProps, 'dispatch'>>
>

@@ -115,4 +113,4 @@ }

*/
export function connectStoreon<ComponentProps>(
...keysOrComponent: Array<PropertyKey | ComponentType<ComponentProps>>
export function connectStoreon<ComponentProps> (
...keysOrComponent: (PropertyKey | ComponentType<ComponentProps>)[]
): connectStoreon.ConnectedComponent<ComponentProps>

@@ -22,3 +22,3 @@ # Storeon

// Initial state, reducers and business logic are packed in independent modules
let increment = store => {
let count = store => {
// Initial state

@@ -30,3 +30,3 @@ store.on('@init', () => ({ count: 0 }))

export const store = createStoreon([increment])
export const store = createStoreon([count])
```

@@ -73,3 +73,3 @@

* [`@storeon/localstorage`](https://github.com/storeon/localstorage)
saves and restores state to `localStorage`.
saves and restores state to `localStorage` or `sessionStorage`.
* [`@storeon/crosstab`](https://github.com/storeon/crosstab)

@@ -87,6 +87,6 @@ synchronizes events between browser tabs.

and routes modification on the fly.
* [`koddr/storeon-sessionstorage`](https://github.com/koddr/storeon-sessionstorage)
saves and restores state to `sessionStorage` (based on [`@storeon/localstorage`](https://github.com/storeon/localstorage)).
* [`mariosant/storeon-streams`](https://github.com/mariosant/storeon-streams)
is side effects management library.
* [`octav47/storeonize`](https://github.com/octav47/storeonize)
is migrating tool from Redux to Storeon.

@@ -114,7 +114,6 @@ ## Install

The store should be created with `createStoreon()` function. It accepts a list
of the modules.
The store should be created with the `createStoreon()` function. It accepts a list
of functions.
Each module is just a function, which will accept a `store`
and bind their event listeners.
Each function should accept a `store` as the only argument and bind their event listeners using `store.on()`.

@@ -154,6 +153,5 @@ ```js

* `@init` will be fired in `createStoreon`. The best moment to set
an initial state.
* `@init` will be fired in `createStoreon`. Bind to this event to set the initial state.
* `@dispatch` will be fired on every new action (on `store.dispatch()` calls
and `@changed` event). It receives an array with the event name
and `@changed` events). It receives an array with the event name
and the event’s data. Can be useful for debugging.

@@ -163,3 +161,3 @@ * `@changed` will be fired when any event changes the state.

To add an event listener, call `store.on()` with event name and callback.
To add an event listener, call `store.on()` with the event name and a callback function.

@@ -172,3 +170,3 @@ ```js

`store.on()` will return cleanup function. This function will remove
`store.on()` will return a cleanup function. Calling this function will remove
the event listener.

@@ -192,7 +190,7 @@

Event listener accepts the current state as a first argument
and optional event object as a second.
An event listener accepts the current state as the first argument
and optional event object as the second.
So event listeners can be a reducer as well. As in Redux’s reducers,
you should change immutable.
So event listeners can be reducers as well. As in Redux’s reducers,
your should change immutable.

@@ -226,3 +224,3 @@ ```js

For functional components, `useStoreon` hook will be the best option:
For functional components, the `useStoreon` hook will be the best option:

@@ -244,3 +242,3 @@ ```js

For class components, you can use `connectStoreon()` decorator.
For class components, you can use the `connectStoreon()` decorator.

@@ -285,4 +283,4 @@ ```js

Or if you want to print events to `console` you can use built-in logger.
It could be useful for simple cases or to investigate issue in error trackers.
Or if you want to print events to `console` you can use the built-in logger.
It could be useful for simple cases or to investigate issues in error trackers.

@@ -303,6 +301,6 @@ ```js

Storeon delivers TypeScript declaration which allows to declare type
Storeon delivers TypeScript declarations which allows to declare type
of state and optionally declare types of events and parameter.
If Storeon store has to be full type safe the event types declaration
If a Storeon store has to be fully type safe the event types declaration
interface has to be delivered as second type to `createStore` function.

@@ -354,3 +352,3 @@

In order to work properly for imports, it is considering adding
In order to work properly for imports, consider adding
`allowSyntheticDefaultImports: true` to `tsconfig.json`.

@@ -360,5 +358,5 @@

In order to preload data for server-side rendering, Storeon provide
`customContext` function to create your own `useStoreon` hooks that it will
depends on your custom context.
In order to preload data for server-side rendering, Storeon provides the
`customContext` function to create your own `useStoreon` hooks that
depend on your custom context.

@@ -421,3 +419,3 @@ ```js

We recommend to keep business logic away from the components. In this case,
We recommend to keep business logic away from components. In this case,
UI kit (special page with all your components in all states)

@@ -424,0 +422,0 @@ will be the best way to test components.

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