File tree Expand file tree Collapse file tree 9 files changed +11199
-15667
lines changed
Expand file tree Collapse file tree 9 files changed +11199
-15667
lines changed Original file line number Diff line number Diff line change @@ -7,19 +7,17 @@ const $ = require('jquery');
77
88class CounterM extends Counter {
99 initialRender ( ) {
10-
11- this . dom = $ ( tmpl ( this . __store . getState ( ) ) ) ;
10+ this . dom = $ ( tmpl ( this . getState ( ) ) ) ;
1211 this . disp = this . dom . find ( '[data-role=disp]' ) ;
1312 this . dispatcher = this . dom . find ( '[data-role=action]' ) ;
1413 this . dispatcher . on ( 'click' , ( evt ) => {
15- this . __store . dispatch ( { type : evt . target . dataset . actionType } ) ;
14+ this . dispatch ( { type : evt . target . dataset . actionType } ) ;
1615 } ) ;
1716
1817 $ ( this . __container ) . append ( this . dom ) ;
1918 }
2019 render ( ) {
21- console . log ( this . disp . html ) ;
22- this . disp . html ( this . __store . getState ( ) . count ) ;
20+ this . disp . html ( this . getState ( ) . count ) ;
2321 }
2422}
2523
Original file line number Diff line number Diff line change 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+
14+ module . exports = Images ;
Original file line number Diff line number Diff line change 2222 "jade" : " ~1.11.0" ,
2323 "jquery" : " ^1.12.4" ,
2424 "morgan" : " ~1.7.0" ,
25+ "redux" : " ^3.6.0" ,
2526 "serve-favicon" : " ~2.3.2" ,
2627 "webpack" : " ^2.2.1"
2728 },
Original file line number Diff line number Diff line change 1010
1111class BaseComponent {
1212 constructor ( { initialStore = null , container = document . body } = { } ) {
13- this . __store = null ;
13+ this . __store = initialStore ;
1414 this . __container = container ;
15- if ( initialStore && this . render ) {
16- this . __store = initialStore ;
15+ if ( this . __store ) {
1716 this . __store . subscribe ( ( ) => {
1817 this . render ( ) ;
1918 } ) ;
2019 }
21- this . initialRender && this . initialRender ( ) ;
20+ this . initialRender ( ) ;
21+ }
22+ getState ( ) {
23+ return this . __store . getState ( ) ;
24+ }
25+ dispatch ( action ) {
26+ return this . __store . dispatch ( action ) ;
27+ }
28+ initialRender ( ) {
29+ // InitialRender.
30+ }
31+ render ( ) {
32+ // Render.
2233 }
2334 // constructor({ initialStore = null, initialState = {}, container = document.body } = {}) {
2435 // if (initialStore && initialStore instanceof Storage) {
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1+ function count ( state = 0 , action ) {
2+ switch ( action . type ) {
3+ case 'UP' :
4+ return state + 1 ;
5+ case 'DOWN' :
6+ return state + 2 ;
7+ default :
8+ return state ;
9+ }
10+ }
11+
12+ function images ( state = [ ] , action ) {
13+ if ( action . type === 'ADD_IMAGE' ) {
14+ return Array . from ( state ) . push ( action . url ) ;
15+ } else if ( action . type === 'REMOVE_IMAGE' ) {
16+ return Array . from ( state ) . splice ( 0 , state . length - 1 ) ;
17+ } else {
18+ return state ;
19+ }
20+ }
21+
22+ module . exports = {
23+ count,
24+ images,
25+ } ;
Original file line number Diff line number Diff line change 2727//
2828const { createStore, combineReducers } = require ( 'redux' ) ;
2929const dr = require ( 'domready' ) ;
30+ const initialState = {
31+ count : 0 ,
32+ images : [
33+ 'https://camo.githubusercontent.com/f28b5bc7822f1b7bb28a96d8d09e7d79169248fc/687474703a2f2f692e696d6775722e636f6d2f4a65567164514d2e706e67' ,
34+ 'https://camo.githubusercontent.com/f28b5bc7822f1b7bb28a96d8d09e7d79169248fc/687474703a2f2f692e696d6775722e636f6d2f4a65567164514d2e706e67' ,
35+ ]
36+ } ;
3037
31- const store = createStore ( combineReducers ( {
32- count : count
33- } ) , { count : 0 } ) ;
38+ const dealDetailReducers = require ( 'dealDetailReducer' ) ;
39+ const store = createStore ( combineReducers ( dealDetailReducers ) , initialState ) ;
3440
3541const CounterM = require ( 'CounterM' ) ;
42+ const Images = require ( 'Images' ) ;
3643
37- let counter = new CounterM ( { initialStore : store , container : document . querySelector ( '#counter' ) } ) ;
38-
39- function count ( state = 0 , action ) {
40- switch ( action . type ) {
41- case 'UP' :
42- return state + 1 ;
43- case 'DOWN' :
44- return state + 2 ;
45- default :
46- return state ;
47- }
48- }
44+ dr ( ( ) => {
45+ let counter = new CounterM ( { initialStore : store , container : document . querySelector ( '#counter' ) } ) ;
46+ let images = new Images ( { initialStore : store , container : document . querySelector ( '#images' ) } ) ;
47+ } ) ;
Original file line number Diff line number Diff line change 1+ <ul >
2+ {{ #each images as |img |}}
3+ <li ><img src =" {{ img }} " /></li >
4+ {{ /each }}
5+ </ul >
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ block content
55 h1 딜상세페이지
66 div( id ="wrapper" )
77 section( id ="counter" )
8+ section( id ="images" )
89
910 //- script(src='./js/redux.bundle.js')
1011 script( src ='./js/redux.bundle.js' )
You can’t perform that action at this time.
0 commit comments