git ssb

16+

Dominic / patchbay



Commit a5b19e9a7af23f8f2cfcf33116137fad4143479b

rework main.js to be requireable

mixmix committed on 10/29/2018, 4:42:26 AM
Parent: e3fb75e68b7f21c04566047c2dd8abe81331e252

Files changed

README.mdchanged
main.jschanged
message/html/action/quote.jsadded
message/html/action/reply.jsadded
message/html/layout/default.mcsschanged
post-patchcore/message/html/action/quote.jsdeleted
post-patchcore/message/html/action/reply.jsdeleted
README.mdView
@@ -163,8 +163,31 @@
163163
164164 Giving modules here will add settings sections to the settings page (`app.page.settings`).
165165
166166
167 +### Requiring the core of patchbay
168 +
169 +If you don't want the default modules, you can grab the main part of patchbay and pick and choose modules like this:
170 +
171 +```js
172 +const patchcore = require('patchcore')
173 +const patchbay = require('patchbay/main')
174 +const combine = require('depject')
175 +const entry = require('depject/entry')
176 +const nest = require('depnest')
177 +
178 +const sockets = combine(
179 + require('patchbay-dark-crystal'), // the module(s) you want
180 + patchbay,
181 + patchcore // required
182 +)
183 +
184 +const api = entry(sockets, nest('app.html.app', 'first'))
185 +document.body.appendChild(api.app.html.app())
186 +```
187 +
188 +You'll need to be running your own sbot and launch this with electro / electron. See `index.js` to see that
189 +
167190 ### How to add a new page
168191
169192 e.g. to add a 'cats' page to the app:
170193
main.jsView
@@ -5,8 +5,12 @@
55
66 // polyfills
77 require('setimmediate')
88
9 +const patchcore = require('patchcore')
10 +delete patchcore.patchcore.message.html.action.reply
11 +// prune an action we don't want
12 +
913 const patchbay = {
1014 patchbay: {
1115 about: bulk(__dirname, [ 'about/**/*.js' ]),
1216 app: bulk(__dirname, [ 'app/**/*.js' ]),
@@ -22,41 +26,27 @@
2226 contextMenu: require('patch-context'),
2327 suggestions: require('patch-suggest'),
2428 settings: require('patch-settings'),
2529 drafts: require('patch-drafts'),
26- inbox: require('patch-inbox'), // TODO - ideally this would be a standalone patch-* module
2730 history: require('patch-history')
2831 }
2932 }
30-
31-const post = {
32- patchbay: {
33- message: bulk(__dirname, [ 'post-patchcore/message/**/*.js' ])
34- }
35-}
36-
37-// from more specialized to more general
38-const sockets = combine(
39- require('patchbay-scry'),
40- require('patchbay-dark-crystal'),
41- require('patchbay-poll'),
42- require('ssb-chess-mithril'),
43- require('patchbay-gatherings'),
44- require('patchbay-book'),
45- patchbay,
46- require('patchcore'),
47- post
48-)
49-
50-// remove patchcore reply for our version
51-var pcReplyIndex = sockets.message.html.action.findIndex(x => x.name === 'reply')
52-if (pcReplyIndex !== -1) { delete sockets.message.html.action[pcReplyIndex] }
53-
54-const api = entry(sockets, nest('app.html.app', 'first'))
55-const app = api.app.html.app
56-
5733 module.exports = patchbay
5834
5935 // for electro[n]
6036 if (typeof window !== 'undefined') {
61- document.body.appendChild(app())
37 + // modules loaded first over-ride core modules loaded later
38 + const sockets = combine(
39 + require('patchbay-scry'),
40 + require('patchbay-dark-crystal'),
41 + require('patchbay-poll'),
42 + require('ssb-chess-mithril'),
43 + require('patchbay-gatherings'),
44 + require('patchbay-book'),
45 + require('patch-inbox'), // TODO needs work
46 + patchbay,
47 + patchcore
48 + )
49 +
50 + const api = entry(sockets, nest('app.html.app', 'first'))
51 + document.body.appendChild(api.app.html.app())
6252 }
message/html/action/quote.jsView
@@ -1,0 +1,17 @@
1 +var h = require('mutant/h')
2 +var nest = require('depnest')
3 +
4 +exports.needs = nest({
5 + 'app.sync.goTo': 'first'
6 +})
7 +
8 +exports.gives = nest('message.html.action')
9 +
10 +exports.create = (api) => {
11 + return nest('message.html.action', function quote (msg) {
12 + return h('a', {
13 + href: '#',
14 + 'ev-click': (ev) => { ev.preventDefault(); api.app.sync.goTo({ action: 'quote', key: msg.key, value: msg.value }) }
15 + }, 'Quote')
16 + })
17 +}
message/html/action/reply.jsView
@@ -1,0 +1,17 @@
1 +var h = require('mutant/h')
2 +var nest = require('depnest')
3 +
4 +exports.needs = nest({
5 + 'app.sync.goTo': 'first'
6 +})
7 +
8 +exports.gives = nest('message.html.action')
9 +
10 +exports.create = (api) => {
11 + return nest('message.html.action', function betterReply (msg) {
12 + return h('a', {
13 + href: '#',
14 + 'ev-click': (ev) => { ev.preventDefault(); api.app.sync.goTo({ action: 'reply', key: msg.key, value: msg.value }) }
15 + }, 'Reply')
16 + })
17 +}
message/html/layout/default.mcssView
@@ -71,16 +71,18 @@
7171 }
7272 }
7373
7474 div.actions {
75- display: flex
76- justify-content: flex-end
75 + display: grid
76 + grid-auto-flow: column
7777
7878 font-size: .9rem
7979 a {
8080 margin-left: .5em
8181 }
8282
83 + a.likes { grid-column: 1 }
84 + a.like, a.unlike { grid-column: 2 }
8385 a.unlike {
8486 $textSubtle
8587 }
8688 }
post-patchcore/message/html/action/quote.jsView
@@ -1,17 +1,0 @@
1-var h = require('mutant/h')
2-var nest = require('depnest')
3-
4-exports.needs = nest({
5- 'app.sync.goTo': 'first'
6-})
7-
8-exports.gives = nest('message.html.action')
9-
10-exports.create = (api) => {
11- return nest('message.html.action', function quote (msg) {
12- return h('a', {
13- href: '#',
14- 'ev-click': (ev) => { ev.preventDefault(); api.app.sync.goTo({ action: 'quote', key: msg.key, value: msg.value }) }
15- }, 'Quote')
16- })
17-}
post-patchcore/message/html/action/reply.jsView
@@ -1,17 +1,0 @@
1-var h = require('mutant/h')
2-var nest = require('depnest')
3-
4-exports.needs = nest({
5- 'app.sync.goTo': 'first'
6-})
7-
8-exports.gives = nest('message.html.action')
9-
10-exports.create = (api) => {
11- return nest('message.html.action', function reply (msg) {
12- return h('a', {
13- href: '#',
14- 'ev-click': (ev) => { ev.preventDefault(); api.app.sync.goTo({ action: 'reply', key: msg.key, value: msg.value }) }
15- }, 'Reply')
16- })
17-}

Built with git-ssb-web