-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract hover state by creating a global state
- Loading branch information
Showing
6 changed files
with
85 additions
and
13 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
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,25 @@ | ||
export default function createStore(initialState) { | ||
let state = initialState; | ||
const listeners = []; | ||
|
||
function setState(partial) { | ||
state = { ...state, ...partial }; | ||
for (let i = 0; i < listeners.length; i++) { | ||
listeners[i](); | ||
} | ||
} | ||
|
||
function getState() { | ||
return state; | ||
} | ||
|
||
function subscribe(listener) { | ||
listeners.push(listener); | ||
} | ||
|
||
return { | ||
setState, | ||
getState, | ||
subscribe, | ||
}; | ||
} |
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 @@ | ||
|
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 @@ | ||
const expect = require('expect.js'); | ||
const createStore = require('../src/createStore'); | ||
|
||
describe('createStore', () => { | ||
it('create with initial state', () => { | ||
const store = createStore({ a: 1 }); | ||
expect(store.getState()).to.eql({ a: 1 }); | ||
}); | ||
|
||
it('setState', () => { | ||
const store = createStore({ a: 1 }); | ||
store.setState({ a: 2 }); | ||
expect(store.getState()).to.eql({ a: 2 }); | ||
}); | ||
|
||
it('subscribe', () => { | ||
const store = createStore({ a: 1 }); | ||
store.subscribe(() => { | ||
expect(store.getState()).to.eql({ a: 2 }); | ||
}); | ||
store.setState({ a: 2 }); | ||
}); | ||
}); |
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,5 +1,2 @@ | ||
require('./basic.spec.js'); | ||
require('./groupingColumnTitle.spec.js'); | ||
require('./rowClick.spec.js'); | ||
require('./fixedColumns.spec.js'); | ||
require('./ColumnManager.spec.js'); | ||
const req = require.context('.', false, /\.spec\.js$/); | ||
req.keys().forEach(req); |