Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Losina24 authored Oct 14, 2022
2 parents 54ab02a + 3aa449a commit 57eb336
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch

## Unreleased

## [1.1.1](https://github.com/kuasr/flux/tree/1.1.1)
### Fix
- *Fix dispatcher emitting changes.* @Losina24

## [1.1.0](https://github.com/kuasr/flux/tree/1.1.0)
### Change
- *Modify dispatcher to allow multiple instances.* @Losina24
Expand Down
2 changes: 1 addition & 1 deletion build/Dispatcher/Dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Dispatcher {
}
}
isBusy() {
return !this.isDispatching;
return this.isDispatching;
}
thunkNotExists(id) {
return this.thunks[id] == undefined;
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuasr-flux",
"version": "1.1.0",
"version": "1.1.1",
"description": "Flux architecture implementation used in Kuasr projects",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"@types/fbemitter": "^2.0.32",
"fbemitter": "^3.0.0",
"immutable": "^4.1.0",
"tsc": "^2.0.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/Dispatcher/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Dispatcher<T extends Action> {
}

public isBusy(): boolean {
return !this.isDispatching
return this.isDispatching
}

private thunkNotExists(id: DispatchToken): boolean {
Expand Down
21 changes: 9 additions & 12 deletions tests/Integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import chai from "chai";
import {Action, ActionThunk, Dispatcher, DispatchToken, Store} from "../src";
import {after, before} from "mocha";
import Immutable from "immutable";

const expect = chai.expect
const dispatcher: Dispatcher<Action> = new Dispatcher<Action>()

class ActionT extends Action{
constructor() {
super('action', 'action');
super('action', true);
}
}

class State {
constructor(public value: Map<string, boolean>) {}
constructor(public value: Immutable.Map<string, boolean>) {}
}

class DummyStore extends Store<State> {
Expand All @@ -22,31 +23,27 @@ class DummyStore extends Store<State> {
}

getInitialState(): State {
return new State(new Map<string, boolean>())
return new State(Immutable.Map<string, boolean>())
}

reduce(state: State, action: Action): any {
if(action.type == 'action') return state.value
reduce(state: State, action: ActionT): State {
if(action.type == 'action') return new State(Immutable.Map<string,boolean>().set('action', true))
return state
}

}

const testIntegration = () => describe('Testing module', () => {
let action: ActionT = new ActionT()
let a = 0
let thunk: ActionThunk<ActionT> = new ActionThunk((action: ActionT) => {
if (action.type == 'action') a = 1
})
let token: DispatchToken
let store: DummyStore = new DummyStore(dispatcher)


before(() => {
token = dispatcher.register(thunk)
dispatcher.dispatch(action)
})

it('should be able to change the state', () => {
expect(a == 1).to.be.true
expect(store.getState().value.get('action') == true).to.be.true
});
})

Expand Down
8 changes: 7 additions & 1 deletion tests/Store.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import chai from "chai";
import {Store, Dispatcher} from '../src'
import Immutable from "immutable"

const expect = chai.expect

class FooStore extends Store<any> {
getInitialState() {
return new Map<string, boolean>();
return Immutable.Map()
}

constructor(dispatcher: Dispatcher<any>) {
Expand Down Expand Up @@ -92,6 +93,11 @@ const testStore = () => describe('Testing Store', () => {
});

expect(store.getState().get('foo')).to.be.equal(100);

dispatch({type: 'boom'});

expect(store.getState().get('foo')).to.be.equal(undefined);
expect(store.getState().has('foo')).to.be.equal(false);
});
})

Expand Down

0 comments on commit 57eb336

Please sign in to comment.