Comparing version 0.9.7 to 0.9.8
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 0.9.8 | ||
* Fix TypeScript definitions (by @majo44). | ||
## 0.9.7 | ||
@@ -5,0 +8,0 @@ * Reduce package size. |
@@ -5,26 +5,36 @@ type DataTypes<Map, Key extends keyof Map> = | ||
declare namespace createStore { | ||
export type Dispatch<EventsDataTypesMap> = (<Event extends keyof EventsDataTypesMap>( | ||
event: Event, ...data: DataTypes<Partial<EventsDataTypesMap>, Event>) => void) & {___events: EventsDataTypesMap}; | ||
export type Dispatch<Events> = (<Event extends keyof Events>( | ||
event: Event, ...data: DataTypes<Partial<Events>, Event>) => void) & {___events: Events}; | ||
export interface Store<State = unknown, EventsDataTypesMap = any> { | ||
readonly on: <Event extends keyof EventsDataTypesMap>( | ||
export type DispatchEvent<State, Events, Event extends keyof Events = keyof Events> = | ||
[Event, Events[Event], Array<StoreonEventHandler<State, Events, Event>>]; | ||
export type StoreonEventHandler<State, Events, Event extends keyof (Events & StoreonEvents<State, Events>)> = | ||
(state: Readonly<State>, data: (Events & StoreonEvents<State, Events>)[Event]) => Partial<State> | Promise<void> | null | void; | ||
export interface Store<State = unknown, Events = any> { | ||
readonly on: <Event extends keyof (Events & StoreonEvents<State, Events>)>( | ||
event: Event, | ||
handler: (state: Readonly<State>, data: EventsDataTypesMap[Event]) => Partial<State> | Promise<void> | null | void | ||
handler: StoreonEventHandler<State, Events, Event> | ||
) => () => void; | ||
readonly dispatch: Dispatch<EventsDataTypesMap>; | ||
readonly dispatch: Dispatch<Events & DispatchableStoreonEvents<State>>; | ||
readonly get: () => State; | ||
} | ||
export type Module<State, EventsDataTypesMap = any> = (store: Store<State, EventsDataTypesMap>) => void; | ||
export type Module<State, Events = any> = (store: Store<State, Events>) => void; | ||
export interface StoreonEvents<State> { | ||
export interface DispatchableStoreonEvents<State> { | ||
'@init': never; | ||
'@changed': State; | ||
} | ||
export interface StoreonEvents<State, Events = any> extends DispatchableStoreonEvents<State>{ | ||
'@dispatch': DispatchEvent<State, Events & DispatchableStoreonEvents<State>>; | ||
} | ||
} | ||
declare function createStore<State, EventsDataTypesMap = any>( | ||
modules: Array<createStore.Module<State, EventsDataTypesMap> | false> | ||
): createStore.Store<State, EventsDataTypesMap & createStore.StoreonEvents<State>>; | ||
declare function createStore<State, Events = any>( | ||
modules: Array<createStore.Module<State, Events> | false> | ||
): createStore.Store<State, Events>; | ||
export = createStore; |
{ | ||
"name": "storeon", | ||
"version": "0.9.7", | ||
"version": "0.9.8", | ||
"description": "Tiny (175 bytes) event-based Redux-like state manager for React and Preact", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -75,2 +75,4 @@ # Storeon | ||
allows undoing or redoing the latest event. | ||
* [`@storeon/websocket`](https://github.com/storeon/websocket) | ||
to sync actions through WebSocket. | ||
@@ -82,2 +84,4 @@ Third-party tools: | ||
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)). | ||
@@ -143,6 +147,6 @@ | ||
an initial state. | ||
* `@dispatch` will be fired on every `store.dispatch()` call. | ||
* `@dispatch` will be fired on every new action (on `store.dispatch()` calls and `@changed` event). | ||
It receives an array with the event name and the event’s data. | ||
Can be useful for debugging. | ||
* `@changed` will be fired every when event listeners changed the state. | ||
* `@changed` will be fired when any event changes the state. | ||
It receives object with state changes. | ||
@@ -285,3 +289,3 @@ | ||
```typescript | ||
import createStore, { Module, StoreonEvents } from 'storeon' | ||
import createStore, { Module } from 'storeon' | ||
import useStoreon from 'storeon/react' // or storeon/preact | ||
@@ -295,3 +299,3 @@ | ||
// Events declaration: map of event names to type of event data | ||
interface Events extends StoreonEvents<State> { | ||
interface Events { | ||
// `inc` event which do not goes with any data | ||
@@ -330,3 +334,6 @@ 'inc': undefined | ||
In order to work properly for imports, it is considering adding | ||
`allowSyntheticDefaultImports: true` to `tsconfig.json`. | ||
## Testing | ||
@@ -333,0 +340,0 @@ |
28860
480
362