Skip to content

Commit 67b91bc

Browse files
authored
Merge pull request #1 from dalgos/feature/v0.1.0
Feature/v0.1.0
2 parents 0bbf2e8 + d2baeb0 commit 67b91bc

File tree

16 files changed

+20120
-6203
lines changed

16 files changed

+20120
-6203
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: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
//hbs
2-
//dispatch
3-
41
const tmpl = require('hbs/counter.hbs');
52
const Counter = require('Counter');
63
const $ = require('jquery');
74

85
class CounterM extends Counter {
96
initialRender() {
10-
11-
this.dom = $(tmpl(this.__store.getState()));
7+
this.dom = $(tmpl(this.getState()));
128
this.disp = this.dom.find('[data-role=disp]');
139
this.dispatcher = this.dom.find('[data-role=action]');
1410
this.dispatcher.on('click', (evt) => {
15-
this.__store.dispatch({ type: evt.target.dataset.actionType });
11+
this.dispatch({ type: evt.target.dataset.actionType });
1612
});
17-
1813
$(this.__container).append(this.dom);
1914
}
2015
render() {
21-
console.log(this.disp.html);
22-
this.disp.html(this.__store.getState().count);
16+
this.disp.html(this.getState().count);
2317
}
2418
}
2519

ViewComponents/Images.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+
const tmpl = require('hbs/images');
3+
const $ = require('jquery');
4+
5+
class Images extends BaseComponent {
6+
initialRender() {
7+
$(this.__container).append(tmpl(this.getState()));
8+
}
9+
render() {
10+
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+
25+
}
26+
}
27+
28+
module.exports = Images;

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;

libs/Storage/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { createStore, combineReducers } = require('redux');
2+
3+
let __store;
4+
5+
class Storage {
6+
constructor({ reducers = {}, initialState = {} } = {}) {
7+
__store = createStore(combineReducers(reducers), initialState);
8+
}
9+
subscribe(render) {
10+
__store.subscribe(render);
11+
}
12+
getState() {
13+
return __store.getState();
14+
}
15+
dispatch(action) {
16+
console.log(action);
17+
__store.dispatch(action);
18+
}
19+
}
20+
21+
module.exports = Storage;

parents/BaseComponent.js

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

parents/Counter.js

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

parents/Storage.js

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

0 commit comments

Comments
 (0)