Commit a5b19e9a7af23f8f2cfcf33116137fad4143479b
rework main.js to be requireable
mixmix committed on 10/29/2018, 4:42:26 AMParent: e3fb75e68b7f21c04566047c2dd8abe81331e252
Files changed
README.md | ||
---|---|---|
@@ -163,8 +163,31 @@ | ||
163 | 163 … | |
164 | 164 … | Giving modules here will add settings sections to the settings page (`app.page.settings`). |
165 | 165 … | |
166 | 166 … | |
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 … | + | |
167 | 190 … | ### How to add a new page |
168 | 191 … | |
169 | 192 … | e.g. to add a 'cats' page to the app: |
170 | 193 … |
main.js | ||
---|---|---|
@@ -5,8 +5,12 @@ | ||
5 | 5 … | |
6 | 6 … | // polyfills |
7 | 7 … | require('setimmediate') |
8 | 8 … | |
9 … | +const patchcore = require('patchcore') | |
10 … | +delete patchcore.patchcore.message.html.action.reply | |
11 … | +// prune an action we don't want | |
12 … | + | |
9 | 13 … | const patchbay = { |
10 | 14 … | patchbay: { |
11 | 15 … | about: bulk(__dirname, [ 'about/**/*.js' ]), |
12 | 16 … | app: bulk(__dirname, [ 'app/**/*.js' ]), |
@@ -22,41 +26,27 @@ | ||
22 | 26 … | contextMenu: require('patch-context'), |
23 | 27 … | suggestions: require('patch-suggest'), |
24 | 28 … | settings: require('patch-settings'), |
25 | 29 … | drafts: require('patch-drafts'), |
26 | - inbox: require('patch-inbox'), // TODO - ideally this would be a standalone patch-* module | |
27 | 30 … | history: require('patch-history') |
28 | 31 … | } |
29 | 32 … | } |
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 | - | |
57 | 33 … | module.exports = patchbay |
58 | 34 … | |
59 | 35 … | // for electro[n] |
60 | 36 … | 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()) | |
62 | 52 … | } |
message/html/action/quote.js | ||
---|---|---|
@@ -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.js | |||
---|---|---|---|
@@ -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.mcss | ||
---|---|---|
@@ -71,16 +71,18 @@ | ||
71 | 71 … | } |
72 | 72 … | } |
73 | 73 … | |
74 | 74 … | div.actions { |
75 | - display: flex | |
76 | - justify-content: flex-end | |
75 … | + display: grid | |
76 … | + grid-auto-flow: column | |
77 | 77 … | |
78 | 78 … | font-size: .9rem |
79 | 79 … | a { |
80 | 80 … | margin-left: .5em |
81 | 81 … | } |
82 | 82 … | |
83 … | + a.likes { grid-column: 1 } | |
84 … | + a.like, a.unlike { grid-column: 2 } | |
83 | 85 … | a.unlike { |
84 | 86 … | $textSubtle |
85 | 87 … | } |
86 | 88 … | } |
post-patchcore/message/html/action/quote.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -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