Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
firatkiral committed May 14, 2022
1 parent b089553 commit 1eef9cf
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 78 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# StateMesh - A State Manager for JavaScript
# StateMesh - Lightweight State Manager

This library provides powerful and lightweight state machine with support for lazy evaluation, immediate evaluation, nested states and value caching.
Any change on the states propagates to the app so app can react to the change at time of the change or wait until the end of the app loop.
Expand Down Expand Up @@ -67,27 +67,27 @@ userState.set({

```

## StateMesh
## StateGroup

StateMesh allows us to create nested states. We can think of it as a container for all states.
We can create a tree of states by adding StateMeshes recursively. In this example we'll create a simple
StateGroup allows us to create nested states. We can think of it as a container for all states.
We can create a tree of states by adding StateGroups recursively. In this example we'll create a simple
app with basic states.

```javascript
const appState = new StateMesh().addState(
const appState = new StateGroup().addState(
new State("user", {
username: 'johndoe',
email: '[email protected]',
membership: 'basic'
}),
new StateMesh("project").addState(
new StateGroup("project").addState(
new State("details", {
name: 'My Project',
description: 'This is my project'
}),
new State("coverUrl", "./cover.png"),
new State("assets", ["./img.png", "./img2.png"]),
new StateMesh("settings").addState(
new StateGroup("settings").addState(
new State("theme", "light"),
new State("fontSize", 16),
new State("fontFamily", "monospace"),
Expand Down
26 changes: 9 additions & 17 deletions dist/statemesh.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export declare class State<T> {
};
removeChangeListener(listener: (val: T | undefined) => void): this;
clearChangeListeners(): this;
addListener(listener: () => void): {
addInvalidationListener(listener: () => void): {
listener: () => void;
destroy: () => void;
};
removeListener(listener: () => void): this;
clearListeners(): this;
removeInvalidationListener(listener: () => void): this;
clearInvalidationListeners(): this;
isValid(): boolean;
protected validate(): void;
protected invalidate(): void;
Expand All @@ -33,25 +33,17 @@ export declare class State<T> {
set(newValue: T): this;
get(): T | undefined;
}
export declare class Binding<T> extends State<T> {
export declare class StateGroup extends State<any> {
#private;
[key: string]: any;
constructor(name?: string, computeFn?: (...args: any) => T | undefined);
constructor(name?: string, computeFn?: (...args: any) => any);
addState(...inputs: State<any>[]): this;
removeState(...inputs: State<any>[]): this;
removeStateAt(idx: number): this;
clearStates(): this;
getStates(): State<any>[];
set(newValue: T): this;
get(): T | undefined;
compute(...args: any): T | undefined;
setComputeFn(computeFn?: (...args: any) => T | undefined): this;
}
interface Mesh {
[key: string]: any;
}
export declare class StateMesh extends Binding<Mesh> {
constructor(name: string);
compute(...args: any): Mesh;
set(newValue: any): this;
get(): any;
compute(...args: any): any;
setComputeFn(computeFn?: (...args: any) => any): this;
}
export {};
2 changes: 1 addition & 1 deletion dist/statemesh.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/statemesh.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1eef9cf

Please sign in to comment.