Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
shmoop207 committed Jan 9, 2019
1 parent 32f82f9 commit 16e3924
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 52 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -33,7 +33,7 @@ store.setState({counter: 1});

```

#### `get currentState():T`
#### `state():T`
return copy of the current state
```javascript
import {Store} from "appolo-store"
Expand All @@ -42,7 +42,7 @@ import {Store} from "appolo-store"

store.setState({counter: 1});

let state = store.currentState
let state = store.state()


```
Expand Down Expand Up @@ -78,7 +78,7 @@ store.setState({counter: 1});
store.setState({counter: 2});
store.goToState(1);

store.currentState.counter // 1
store.state().counter // 1

```

Expand Down Expand Up @@ -156,7 +156,7 @@ let store = new Store<{ counter: number }>({counter: 0});
store.setState({counter: 1});
store.setState({counter: 2});

for (let state of store.states) {
for (let state of store.states()) {
console.log(state.counter) // 0 ,1 ,2
}

Expand All @@ -174,7 +174,7 @@ store.setState({counter: 2});

store.reset()

store.currentState.counter // 0
store.state().counter // 0

```

Expand Down
2 changes: 1 addition & 1 deletion lib/action.js

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

2 changes: 1 addition & 1 deletion lib/action.ts
Expand Up @@ -26,7 +26,7 @@ export function action(name?: string): (target: any, propertyKey: string, descri
result = await result;
}

this.fireEvent(name || propertyKey, this.currentState);
this.fireEvent(name || propertyKey, this.state());

return result;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/store.js

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

15 changes: 8 additions & 7 deletions lib/store.ts
Expand Up @@ -32,11 +32,11 @@ export class Store<T extends { [index: string]: any }> extends EventDispatcher {
return this.initialState as T;
}

public get currentState(): T {
public state(): T {
return this.stateAt(this._stateIndex);
}

public get states(): IterableIterator<T> {
public states(): IterableIterator<T> {

let $self = this, index = -1;

Expand Down Expand Up @@ -71,7 +71,7 @@ export class Store<T extends { [index: string]: any }> extends EventDispatcher {
}

public setState(value: Partial<T> | T, options: { arrayMerge?: "override" | "extend" } = {arrayMerge: "extend"}) {
let state = this.currentState;
let state = this.state;

let mergeOptions: any = {};

Expand All @@ -87,13 +87,14 @@ export class Store<T extends { [index: string]: any }> extends EventDispatcher {

this._states.push(newState as T);

this._stateIndex = this.countIndex;

if (this.count > this.MaxStates) {
this._states.shift();
}

this.fireEvent("stateChanged", this.currentState);
this._stateIndex = this.countIndex;


this.fireEvent("stateChanged", this.state());
}

public get count(): number {
Expand Down Expand Up @@ -137,7 +138,7 @@ export class Store<T extends { [index: string]: any }> extends EventDispatcher {
this._stateIndex = index;

if (oldIndex != this._stateIndex) {
this.fireEvent("stateChanged", this.currentState);
this.fireEvent("stateChanged", this.state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -18,7 +18,7 @@
"test": "mocha test"
},
"main": "./index.js",
"version": "0.0.5",
"version": "0.0.6",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
30 changes: 15 additions & 15 deletions test/unit.js

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

0 comments on commit 16e3924

Please sign in to comment.