-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redux Injector (Enables bindings between redux and dojo 2 widget-core) (
#2) * redux injector * add dojo/interfaces dependency * add tests for redux injector * Add redux to intern config * add other config for intern * move redux to optional dependency
- Loading branch information
Showing
5 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Store } from 'redux'; | ||
import { Base } from '@dojo/widget-core/Injector'; | ||
|
||
/** | ||
* Injector for redux store | ||
*/ | ||
export class ReduxInjector<S = any> extends Base<Store<S>> { | ||
|
||
/** | ||
* Injected redux store | ||
*/ | ||
protected store: Store<S>; | ||
|
||
/** | ||
* Sets the store and attaches the injectors invalidate to the redux | ||
* stores bind. | ||
* | ||
* @param store The store for the injector | ||
*/ | ||
constructor(store: Store<S>) { | ||
super(); | ||
this.store = store; | ||
this.store.subscribe(this.invalidate.bind(this)); | ||
} | ||
|
||
/** | ||
* Returns the value to be injected, in this case the Store | ||
* that was passed when creating the Injector. | ||
* | ||
* @returns Returns the store | ||
*/ | ||
public toInject(): Store<S> { | ||
return this.store; | ||
} | ||
} | ||
|
||
export default ReduxInjector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './main'; | ||
import './redux/ReduxInjector'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as registerSuite from 'intern!object'; | ||
import * as assert from 'intern/chai!assert'; | ||
import { ReduxInjector } from './../../../src/redux/ReduxInjector'; | ||
import { createStore } from 'redux'; | ||
|
||
registerSuite({ | ||
name: 'ReduxInjector', | ||
reduxInjector() { | ||
const store = createStore((state) => state); | ||
const injector = new ReduxInjector(store); | ||
let injectorInvalidated = false; | ||
injector.on('invalidated', () => { | ||
injectorInvalidated = true; | ||
}); | ||
store.dispatch({ type: 'TEST' }); | ||
assert.isTrue(injectorInvalidated); | ||
}, | ||
toInject() { | ||
const store = createStore((state) => state); | ||
const injector = new ReduxInjector(store); | ||
assert.strictEqual(injector.toInject(), store); | ||
} | ||
}); |