Releases: riccardoperra/statebuilder
Release list
statebuilder@0.3.0
Breaking changes
This new version removes withPlugin introduced in 0.2.4. Instead, now plugins will infer automatically the type, and uses a generic signatureby default.
const store = defineSignal(() => 1).extend(
withProxyCommands<{increment: boolean}>())
);
store.hold(
store.commands.increment,
(command, { set }) => {
// ✅ Now `set` is Setter<number> instead of (...args: any) => void
set(v => v + 1);
});Create plugins with store constraints
In order to create plugins that must follow a specific store signature, you can now use the .typed helper of makePlugin function.
const pluginOnlyForStoreLike = () => makePlugin.typed<Store<{ count: number }>>()(store => {
// ...
});
// ❌ pluginOnlyForStoreLike cannot be used anymore since store does not follow the { count : number } state signature
const store1 = defineStore(0).extend(pluginOnlyForStoreLike())What's Changed
- feat: refactor types for implicit inference by @riccardoperra in #13
- chore: update versions by @github-actions in #14
Full Changelog: https://github.com/riccardoperra/statebuilder/compare/statebuilder@0.2.4...statebuilder@0.3.0
statebuilder@0.2.4
What's Changed
- perf: improve types and documentation by @riccardoperra in #9
- perf: remove symbol overhead by @riccardoperra in #11
- chore: update versions by @github-actions in #10
Better store typings with store context
This new version introduces withPlugin, a new utility that can be used to be able to type plugins with the current store, instead of the GenericStoreApi alias. This can be useful when some generic plugins uses the get/setter store api and take advanted of its types to create derived properties
import {defineSignal, withPlugin} from 'statebuilder';
import {withProxyCommands} from 'statebuilder/commands';
const store = defineSignal(() => 1).extend(
withPlugin((ctx) =>
withProxyCommands.of(ctx).with<{ increment: boolean }>(),
),
);
store.hold(
store.commands.increment,
(command, { set }) => {
// ✅ Now `set` is Setter<number> instead of (...args: any) => void
set(v => v + 1);
});Full Changelog: https://github.com/riccardoperra/statebuilder/compare/statebuilder@0.2.3...statebuilder@0.2.4
statebuilder@0.2.3
Patch Changes
- 2788c2c: add reducer plugin
type Increment = { type: 'increment'; payload: number };
type Decrement = { type: 'decrement'; payload: number };
type AppActions = Increment | Decrement;
function appReducer(state: number, action: AppActions) {
switch (action.type) {
case 'increment':
return state + action.payload;
case 'decrement':
return state - action.payload;
default:
return state;
}
}
const $count = defineSignal(() => 1)
.extend(withReducer(appReducer));
const count = provideState($count);
count.dispatch({ type: 'increment', payload: 1 });statebuilder@0.2.2
With this new version of statebuilder you can declare the dependencies that your plugin needs. This is the point where registering name of the plugins become important, because you can reference plugin dependencies by their name;
import { makePlugin } from "statebuilder";
const plugin = makePlugin(() => ({}), {
name: "plugin",
dependencies: ["actionsPlugin"]
});Note While providing the state, if a plugin dependency cannot be resolved an error will be throwned
What's Changed
- feat: add plugin explicit dependency support by @riccardoperra in #4
Full Changelog: https://github.com/riccardoperra/statebuilder/compare/statebuilder@0.2.1...statebuilder@0.2.2
statebuilder@0.2.1
Redux Devtools support
With this new version of statebuilder it's available a new plugin to integrate redux devtools.
import {defineSignal} from 'statesolid';
import {withReduxDevtools} from 'statesolid/devtools';
const state = defineSignal(() => 0).extend(
withReduxDevtools({storeName: 'count-state'})
)What's Changed
- feat: add devtools plugin (beta) by @riccardoperra in #3
Full Changelog: https://github.com/riccardoperra/statebuilder/commits/statebuilder@0.2.1
statesolid@0.2.0
This version refactor the core to be state agnostic and integrates a simple plugin system
Creating signals
A new primitive has been added: defineSignal based on the createSignal solid-js API.
import {defineSignal, provideState} from 'statesolid';
const config = defineSignal(() => 0)
.extend(ctx => ({
increment: () => ctx.set(prev => prev + 1)
});
const count = provideState(config);
count(); // 0;
count.set(1);Creating custom stores
By making the core agnostic, it is possible to define also custom states with the create api.
import {create} from 'statesolid';
import {Setter, createSignal} from 'solid-js';
function factory<T>(initialValue: T, name: string) {
const [state, setState] = createSignal<T>(initialValue);
const set: Setter<T> = (value) => {
setState(value);
localStorage.set(name, state());
}
return Object.assign(state, {
set
});
}
const createLocalStorageSignal = create('signal-with-local-storage', factory);
const config = createLocalStorageSignal(0);Creating custom plugins
import {createEffect} from 'solid-js';
import {makePlugin, defineSignal} from 'statesolid';
export function withEffectOnStateChange<T>(cb: (state: T) => void) {
return makePlugin(
(state) => {
createEffect(() => cb(state()));
},
{
name: 'withCallbackOnStateChange',
},
);
}
const state = defineSignal(() => 0).extend(
withEffectOnStateChange((state) => console.log(state)),
);Creating plugin is now easier thanks to the makePlugin helper
What's Changed
- feat: refactor core to be agnostic by @riccardoperra in #1
- feat: add plugin systems by @riccardoperra in #2
Full Changelog: https://github.com/riccardoperra/statesolid/commits/statesolid@0.2.0