Skip to content

Commit d2baeb0

Browse files
author
Kwangsoo Shin
committed
All: Scafolding, Add getReducers, reducers.
1 parent 229ec41 commit d2baeb0

File tree

12 files changed

+29603
-11115
lines changed

12 files changed

+29603
-11115
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ typings/
6565
# End of https://www.gitignore.io/api/node
6666

6767
# ignore dist folder
68-
public/js/
68+
# public/js/

DataComponents/Counter.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const BaseComponent = require('BaseComponent');
2+
3+
class Counter extends BaseComponent {
4+
static reducers(state = 0, action) {
5+
let ownReducer = Counter.getReducers();
6+
switch(action.type) {
7+
case 'UP':
8+
case 'DOWN':
9+
return ownReducer[action.type](state, action);
10+
default:
11+
return state;
12+
}
13+
}
14+
static getReducers() {
15+
function UP(state = 0, action) {
16+
return state + 1;
17+
}
18+
function DOWN(state = 0, action) {
19+
return state - 1;
20+
}
21+
return {
22+
UP,
23+
DOWN,
24+
};
25+
}
26+
}
27+
28+
module.exports = Counter;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ class Images extends BaseComponent {
88
}
99
render() {
1010

11+
}
12+
/**
13+
* Reducers for Self Component
14+
* @return Function Reducer
15+
*/
16+
static reducers(state = [], action) {
17+
return state;
18+
}
19+
/**
20+
* Return reducer's maps
21+
* @return Object Reducer's map
22+
*/
23+
static getReducers() {
24+
1125
}
1226
}
1327

core/BaseComponent.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const Storage = require('Storage');
2+
3+
class BaseComponent {
4+
constructor({ initialStorage = null, container = document.body } = {}) {
5+
if (!(initialStorage && initialStorage instanceof Storage)) {
6+
this.__storage = new Storage({ reducers: {}, initialState: {} });
7+
} else {
8+
this.__storage = initialStorage;
9+
}
10+
this.__container = container;
11+
this.__storage.subscribe(() => this.render() );
12+
this.initialRender();
13+
}
14+
/**
15+
* Get store's state data.
16+
* @return Object state data.
17+
*/
18+
getState() {
19+
return this.__storage.getState();
20+
}
21+
/**
22+
* Dispatcher for store.
23+
* @param {Object} action Action Object
24+
* @return Undefined
25+
*/
26+
dispatch(action) {
27+
this.__storage.dispatch(action);
28+
}
29+
/**
30+
* Initialize Render
31+
* @return Undefined
32+
*/
33+
initialRender() {
34+
// InitialRender.
35+
}
36+
/**
37+
* Render for store.
38+
* @return Undefined
39+
*/
40+
render() {
41+
// Render.
42+
}
43+
}
44+
45+
module.exports = BaseComponent;

parents/BaseComponent.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

parents/Counter.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)