git ssb

1+

dinoworm 🐛 / catstack



Commit b4d9493405c3fee0d30b85df773d26788528fff5

add layouts domain, add layout and get to page

Michael Williams committed on 2/23/2017, 5:10:27 AM
Parent: 6e8ff9fb789a862b5d5c77785650b21848d350e7

Files changed

README.mdchanged
example/app/pages/home.jschanged
example/app/modules/layout.jsdeleted
example/app/layouts/main.jsadded
example/cats/pages/all.jschanged
example/cats/pages/one.jschanged
lib/Page.jsadded
types/Page.jschanged
types/Layout.jsadded
README.mdView
@@ -181,16 +181,19 @@
181181 ```js
182182 // cats/pages/show.js
183183 module.exports = {
184184 needs: {
185- layout: 'first',
185 + 'app.layouts.main': 'first',
186186 cats: {
187- profile: 'first'
187 + 'elements.profile': 'first',
188 + 'get.show': 'first'
188189 }
189190 },
190191 create: (api) => ({
191192 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
193196 })
194197 }
195198 ```
196199
@@ -199,9 +202,9 @@
199202 ```js
200203 // cats/elements/profile.js
201204 module.exports = {
202205 needs: {
203- html: 'first'
206 + 'inu.html': 'first'
204207 },
205208 create: (api) => ({
206209 view: (cat) => api.html`
207210 <div>${cat.name}</div>
example/app/pages/home.jsView
@@ -1,12 +1,13 @@
11 module.exports = {
22 needs: {
3- inu: { html: 'first' },
4- app: { modules: { layout: 'first' } }
3 + 'inu.html': 'first',
4 + 'app.layouts.main': 'first'
55 },
66 create: (api) => ({
77 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`
910 <div>home!</div>
10- `)
11 + `
1112 })
1213 }
example/app/modules/layout.jsView
@@ -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.jsView
@@ -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.jsView
@@ -2,20 +2,20 @@
22
33 module.exports = {
44 needs: {
55 'inu.html': 'first',
6- 'app.modules.layout': 'first',
6 + 'app.layouts.main': 'first',
77 cats: {
88 'actions.loadAll': 'first',
99 'get.allProps': 'first'
1010 }
1111 },
1212 create: (api) => ({
1313 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`
1818 <ul onload=${handleLoad}>
1919 ${props.cats.map(cat => api.inu.html`
2020 <li>
2121 <a href=${`/cat/${cat.id}`}>
@@ -25,10 +25,8 @@
2525 `)}
2626 </ul>
2727 `
2828
29- return layout(view)
30-
3129 function handleLoad (el) {
3230 dispatch(api.cats.actions.loadAll())
3331 }
3432 }
example/cats/pages/one.jsView
@@ -2,19 +2,16 @@
22
33 module.exports = {
44 needs: {
55 'inu.html': 'first',
6- 'app.modules.layout': 'first',
6 + 'app.layouts.main': 'first',
77 'cats.get.oneProps': 'first'
88 },
99 create: (api) => ({
1010 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 + `
1916 })
2017 }
lib/Page.jsView
@@ -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.jsView
@@ -1,8 +1,8 @@
11 const pipe = require('value-pipe')
2-const Page = require('inu-router/Page')
32
43 const normalizeNeeds = require('../lib/normalizeNeeds')
4 +const Page = require('../lib/Page')
55
66 module.exports = {
77 transform: pipe(
88 normalizeNeeds,
types/Layout.jsView
@@ -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