Commit 8f610eca2bb7c82ab4520dcd17f0816be4901f3b
linting
austinfrey committed on 11/1/2018, 9:22:54 PMParent: 2fc95bb03dc629547fc2632a480d945bf1b89cef
Files changed
index.js | changed |
stores/ledger.js | changed |
views/accounts.js | changed |
views/entries.js | changed |
index.js | ||
---|---|---|
@@ -18,5 +18,4 @@ | ||
18 | 18 … | app.route('/accounts', require('./views/accounts')) |
19 | 19 … | app.route('/*', require('./views/404')) |
20 | 20 … | |
21 | 21 … | module.exports = app.mount('body') |
22 | - |
stores/ledger.js | |||
---|---|---|---|
@@ -1,29 +1,26 @@ | |||
1 | 1 … | const Flume = require('flumedb') | |
2 | 2 … | const Reduce = require('flumeview-reduce') | |
3 | 3 … | const FlumeLog = require('flumelog-offset') | |
4 | -const {pull, once, drain} = require('pull-stream') | ||
4 … | +const { pull, drain } = require('pull-stream') | ||
5 | 5 … | const codec = require('flumecodec') | |
6 | 6 … | ||
7 | 7 … | function ledger (state, emitter) { | |
8 | 8 … | state.accounts = {} | |
9 | 9 … | state.entries = [] | |
10 | 10 … | ||
11 | - const db = Flume(FlumeLog('.test.db', {codec: codec.json})) | ||
12 | - .use('entries', Reduce( 1, entriesReducer, null, null, [])) | ||
11 … | + const db = Flume(FlumeLog('.test.db', { codec: codec.json })) | ||
12 … | + .use('entries', Reduce(1, entriesReducer, null, null, [])) | ||
13 | 13 … | .use('accounts', Reduce(1, accountReducer, null, null, {})) | |
14 | 14 … | ||
15 | - pull(db.accounts.stream({live: true}), drain(acct => console.log('account stream:', acct))) | ||
16 | - pull(db.entries.stream({live: true}), drain(entry => console.log('entries stream:', entry))) | ||
15 … | + const onDone = () => console.log('DONE') | ||
17 | 16 … | ||
18 | - const onDone = () => console.log('DONE') | ||
19 | 17 … | pull(db.accounts.stream(), drain(acctState => { | |
20 | - console.log('ACCOUNT STATE', acctState) | ||
21 | 18 … | state.accounts = acctState | |
22 | 19 … | emitter.emit.RENDER | |
23 | 20 … | }, onDone)) | |
21 … | + | ||
24 | 22 … | pull(db.entries.stream(), drain(entryState => { | |
25 | - console.log('ENTRY STATE', entryState) | ||
26 | 23 … | state.entries = entryState | |
27 | 24 … | emitter.emit.RENDER | |
28 | 25 … | }, onDone)) | |
29 | 26 … | ||
@@ -49,11 +46,11 @@ | |||
49 | 46 … | } | |
50 | 47 … | ||
51 | 48 … | function accountReducer (acc, item) { // TODO account for account creation of existing account | |
52 | 49 … | if (item.type === 'entries') { | |
53 | - const {msg} = item | ||
54 | - const debit = acc[msg.debit].debit += msg.amount | ||
55 | - const credit = acc[msg.credit].credit += msg.amount | ||
50 … | + const { msg } = item | ||
51 … | + acc[msg.debit].debit += msg.amount | ||
52 … | + acc[msg.credit].credit += msg.amount | ||
56 | 53 … | ||
57 | 54 … | return acc | |
58 | 55 … | } | |
59 | 56 … | if (item.type !== 'accounts') return acc | |
@@ -70,6 +67,5 @@ | |||
70 | 67 … | return acc | |
71 | 68 … | } | |
72 | 69 … | } | |
73 | 70 … | ||
74 | - | ||
75 | 71 … | module.exports = ledger |
views/accounts.js | ||
---|---|---|
@@ -8,21 +8,21 @@ | ||
8 | 8 … | h('div.pv2', 'account balances'), |
9 | 9 … | Object.keys(state.accounts).map(key => { |
10 | 10 … | if (state.accounts[key].archived) { |
11 | 11 … | return h('div', [ |
12 | - h('div.dib.strike', {onclick: handleAccountArchive}, state.accounts[key].name), | |
12 … | + h('div.dib.strike', { onclick: handleAccountArchive }, state.accounts[key].name), | |
13 | 13 … | h('div.dib.pr2.strike', state.accounts[key].debit - state.accounts[key].credit) |
14 | 14 … | ]) |
15 | 15 … | } |
16 | 16 … | return h('div', [ |
17 | - h('div.dib.pr2', {onclick: handleAccountArchive}, state.accounts[key].name), | |
18 | - h('div.dib', state.accounts[key].debit - state.accounts[key].credit), | |
17 … | + h('div.dib.pr2', { onclick: handleAccountArchive }, state.accounts[key].name), | |
18 … | + h('div.dib', state.accounts[key].debit - state.accounts[key].credit) | |
19 | 19 … | ]) |
20 | 20 … | }), |
21 | 21 … | h('div', [ |
22 | 22 … | h('div.pt4', 'create a new account'), |
23 | 23 … | h('form.pb3', h('input#account')), |
24 | - h('button', {onclick: handleAccountCreate}, 'create') | |
24 … | + h('button', { onclick: handleAccountCreate }, 'create') | |
25 | 25 … | ]) |
26 | 26 … | ]) |
27 | 27 … | |
28 | 28 … | function handleAccountCreate () { |
views/entries.js | ||
---|---|---|
@@ -1,6 +1,4 @@ | ||
1 | -const fs = require('fs') | |
2 | -const path = require('path') | |
3 | 1 … | const h = require('hyperscript') |
4 | 2 … | const TITLE = 'double - entries' |
5 | 3 … | const Nav = require('../components/nav') |
6 | 4 … | |
@@ -10,39 +8,38 @@ | ||
10 | 8 … | const form = h('form.pv3', [ |
11 | 9 … | h('div.pb2', [ |
12 | 10 … | h('label', 'debit account'), |
13 | 11 … | h('div', h('select#debit', [ |
14 | - h('option', {value: 'true'},'select'), | |
12 … | + h('option', { value: 'true' }, 'select'), | |
15 | 13 … | generateAccountList() |
16 | 14 … | ])) |
17 | 15 … | ]), |
18 | 16 … | h('div.pb2', [ |
19 | 17 … | h('label', 'credit account'), |
20 | 18 … | h('div', h('select#credit', [ |
21 | - h('option', {value: 'true'},'select'), | |
19 … | + h('option', { value: 'true' }, 'select'), | |
22 | 20 … | generateAccountList() |
23 | 21 … | ])) |
24 | 22 … | ]), |
25 | - h('div', h('input#amount.mb2', {placeholder: 'amount'})), | |
26 | - h('div', h('input#description', {placeholder: 'description'})) | |
23 … | + h('div', h('input#amount.mb2', { placeholder: 'amount' })), | |
24 … | + h('div', h('input#description', { placeholder: 'description' })) | |
27 | 25 … | ]) |
28 | 26 … | |
29 | - const submit = h('div.pb3', h('button', {onclick: handleEntry}, 'submit')) | |
27 … | + const submit = h('div.pb3', h('button', { onclick: handleEntry }, 'submit')) | |
30 | 28 … | |
31 | 29 … | return h('body.code.ph3.lh-copy', [ |
32 | 30 … | state.cache(Nav, 'nav').render(), |
33 | 31 … | h('main', [ |
34 | 32 … | form, |
35 | 33 … | submit |
36 | - ]), | |
34 … | + ]) | |
37 | 35 … | ]) |
38 | 36 … | |
39 | - | |
40 | 37 … | function generateAccountList () { |
41 | 38 … | return Object.keys(state.accounts).map(key => { |
42 | 39 … | if (state.accounts[key].archived) return |
43 | 40 … | const name = state.accounts[key].name |
44 | - return h('option', {value: name}, name) | |
41 … | + return h('option', { value: name }, name) | |
45 | 42 … | }) |
46 | 43 … | } |
47 | 44 … | |
48 | 45 … | function handleEntry () { |
@@ -52,8 +49,7 @@ | ||
52 | 49 … | const description = document.getElementById('description').value |
53 | 50 … | |
54 | 51 … | emit('entries', { type: 'entries', msg: { amount, debit, credit, description } }) |
55 | 52 … | } |
56 | - | |
57 | 53 … | } |
58 | 54 … | |
59 | 55 … | module.exports = view |
Built with git-ssb-web