Commit b4d9493405c3fee0d30b85df773d26788528fff5
add layouts domain, add layout and get to page
Michael Williams committed on 2/23/2017, 5:10:27 AMParent: 6e8ff9fb789a862b5d5c77785650b21848d350e7
Files changed
README.md | changed |
example/app/pages/home.js | changed |
example/app/modules/layout.js | deleted |
example/app/layouts/main.js | added |
example/cats/pages/all.js | changed |
example/cats/pages/one.js | changed |
lib/Page.js | added |
types/Page.js | changed |
types/Layout.js | added |
README.md | ||
---|---|---|
@@ -181,16 +181,19 @@ | ||
181 | 181 … | ```js |
182 | 182 … | // cats/pages/show.js |
183 | 183 … | module.exports = { |
184 | 184 … | needs: { |
185 | - layout: 'first', | |
185 … | + 'app.layouts.main': 'first', | |
186 | 186 … | cats: { |
187 | - profile: 'first' | |
187 … | + 'elements.profile': 'first', | |
188 … | + 'get.show': 'first' | |
188 | 189 … | } |
189 | 190 … | }, |
190 | 191 … | create: (api) => ({ |
191 | 192 … | route: '/cats/:catId', |
192 | - view: api.layout((model) => api.cats.profile) | |
193 … | + layout: api.layouts.main, | |
194 … | + get: api.cats.get.show, | |
195 … | + view: api.cats.profile | |
193 | 196 … | }) |
194 | 197 … | } |
195 | 198 … | ``` |
196 | 199 … | |
@@ -199,9 +202,9 @@ | ||
199 | 202 … | ```js |
200 | 203 … | // cats/elements/profile.js |
201 | 204 … | module.exports = { |
202 | 205 … | needs: { |
203 | - html: 'first' | |
206 … | + 'inu.html': 'first' | |
204 | 207 … | }, |
205 | 208 … | create: (api) => ({ |
206 | 209 … | view: (cat) => api.html` |
207 | 210 … | <div>${cat.name}</div> |
example/app/pages/home.js | ||
---|---|---|
@@ -1,12 +1,13 @@ | ||
1 | 1 … | module.exports = { |
2 | 2 … | needs: { |
3 | - inu: { html: 'first' }, | |
4 | - app: { modules: { layout: 'first' } } | |
3 … | + 'inu.html': 'first', | |
4 … | + 'app.layouts.main': 'first' | |
5 | 5 … | }, |
6 | 6 … | create: (api) => ({ |
7 | 7 … | route: '/', |
8 | - view: (model, dispatch) => api.app.modules.layout(model, dispatch)(api.inu.html` | |
8 … | + layout: api.app.layouts.main, | |
9 … | + view: (model, dispatch) => api.inu.html` | |
9 | 10 … | <div>home!</div> |
10 | - `) | |
11 … | + ` | |
11 | 12 … | }) |
12 | 13 … | } |
example/app/modules/layout.js | ||
---|---|---|
@@ -1,15 +1,0 @@ | ||
1 | -module.exports = { | |
2 | - needs: { inu: { html: 'first' } }, | |
3 | - create: (api) => (model, dispatch) => { | |
4 | - return (view) => api.inu.html` | |
5 | - <div> | |
6 | - <nav> | |
7 | - <a href='/'>home</a> | |
8 | - <a href=${`/cats`}>cats party!</a> | |
9 | - <a href='/nope'>nope</a> | |
10 | - </nav> | |
11 | - ${view} | |
12 | - </div> | |
13 | - ` | |
14 | - } | |
15 | -} |
example/app/layouts/main.js | ||
---|---|---|
@@ -1,0 +1,15 @@ | ||
1 … | +module.exports = { | |
2 … | + needs: { 'inu.html': 'first' }, | |
3 … | + create: (api) => (view) => { | |
4 … | + return (model, dispatch) => api.inu.html` | |
5 … | + <div> | |
6 … | + <nav> | |
7 … | + <a href='/'>home</a> | |
8 … | + <a href=${`/cats`}>cats party!</a> | |
9 … | + <a href='/nope'>nope</a> | |
10 … | + </nav> | |
11 … | + ${view(model, dispatch)} | |
12 … | + </div> | |
13 … | + ` | |
14 … | + } | |
15 … | +} |
example/cats/pages/all.js | ||
---|---|---|
@@ -2,20 +2,20 @@ | ||
2 | 2 … | |
3 | 3 … | module.exports = { |
4 | 4 … | needs: { |
5 | 5 … | 'inu.html': 'first', |
6 | - 'app.modules.layout': 'first', | |
6 … | + 'app.layouts.main': 'first', | |
7 | 7 … | cats: { |
8 | 8 … | 'actions.loadAll': 'first', |
9 | 9 … | 'get.allProps': 'first' |
10 | 10 … | } |
11 | 11 … | }, |
12 | 12 … | create: (api) => ({ |
13 | 13 … | route: '/cats', |
14 | - view: (model, dispatch) => { | |
15 | - const layout = api.app.modules.layout(model, dispatch) | |
16 | - const props = api.cats.get.allProps(model) | |
17 | - const view = api.inu.html` | |
14 … | + layout: api.app.layouts.main, | |
15 … | + get: api.cats.get.allProps, | |
16 … | + view: (props, dispatch) => { | |
17 … | + return api.inu.html` | |
18 | 18 … | <ul onload=${handleLoad}> |
19 | 19 … | ${props.cats.map(cat => api.inu.html` |
20 | 20 … | <li> |
21 | 21 … | <a href=${`/cat/${cat.id}`}> |
@@ -25,10 +25,8 @@ | ||
25 | 25 … | `)} |
26 | 26 … | </ul> |
27 | 27 … | ` |
28 | 28 … | |
29 | - return layout(view) | |
30 | - | |
31 | 29 … | function handleLoad (el) { |
32 | 30 … | dispatch(api.cats.actions.loadAll()) |
33 | 31 … | } |
34 | 32 … | } |
example/cats/pages/one.js | ||
---|---|---|
@@ -2,19 +2,16 @@ | ||
2 | 2 … | |
3 | 3 … | module.exports = { |
4 | 4 … | needs: { |
5 | 5 … | 'inu.html': 'first', |
6 | - 'app.modules.layout': 'first', | |
6 … | + 'app.layouts.main': 'first', | |
7 | 7 … | 'cats.get.oneProps': 'first' |
8 | 8 … | }, |
9 | 9 … | create: (api) => ({ |
10 | 10 … | route: '/cat/:catId', |
11 | - view: (model, dispatch) => { | |
12 | - const layout = api.app.modules.layout(model, dispatch) | |
13 | - const props = api.cats.get.oneProps(model) | |
14 | - const view = api.inu.html` | |
15 | - <h1>${props.cat.name}!</h1> | |
16 | - ` | |
17 | - return layout(view) | |
18 | - } | |
11 … | + layout: api.app.layouts.main, | |
12 … | + get: api.cats.get.oneProps, | |
13 … | + view: (props, dispatch) => api.inu.html` | |
14 … | + <h1>${props.cat ? props.cat.name : ''}!</h1> | |
15 … | + ` | |
19 | 16 … | }) |
20 | 17 … | } |
lib/Page.js | ||
---|---|---|
@@ -1,0 +1,26 @@ | ||
1 … | +const assign = require('object-assign') | |
2 … | +const _Page = require('inu-router/Page') | |
3 … | + | |
4 … | +module.exports = Page | |
5 … | + | |
6 … | +function Page (definition) { | |
7 … | + return _Page(assign({}, definition, { | |
8 … | + create: (api) => { | |
9 … | + var page = definition.create(api) | |
10 … | + console.log('page', page) | |
11 … | + // if page given, wrap view in layout | |
12 … | + if (page.layout) { | |
13 … | + page.view = page.layout(page.view) | |
14 … | + } | |
15 … | + // if get given, use get on model | |
16 … | + if (page.get) { | |
17 … | + const _view = page.view | |
18 … | + page.view = (model, dispatch) => { | |
19 … | + const props = page.get(model) | |
20 … | + return _view(props, dispatch) | |
21 … | + } | |
22 … | + } | |
23 … | + return page | |
24 … | + } | |
25 … | + })) | |
26 … | +} |
types/Page.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 … | const pipe = require('value-pipe') |
2 | -const Page = require('inu-router/Page') | |
3 | 2 … | |
4 | 3 … | const normalizeNeeds = require('../lib/normalizeNeeds') |
4 … | +const Page = require('../lib/Page') | |
5 | 5 … | |
6 | 6 … | module.exports = { |
7 | 7 … | transform: pipe( |
8 | 8 … | normalizeNeeds, |
types/Layout.js | ||
---|---|---|
@@ -1,0 +1,14 @@ | ||
1 … | +const pipe = require('value-pipe') | |
2 … | + | |
3 … | +const pathModule = require('../lib/pathModule') | |
4 … | +const Module = require('../lib/module') | |
5 … | +const normalizeNeeds = require('../lib/normalizeNeeds') | |
6 … | + | |
7 … | +module.exports = { | |
8 … | + transform: pipe( | |
9 … | + pathModule, | |
10 … | + normalizeNeeds, | |
11 … | + Module | |
12 … | + ), | |
13 … | + glob: '**/layouts/*.js' | |
14 … | +} |
Built with git-ssb-web