git ssb

0+

punkmonk / double



Commit 741b824742f41b309cb66ec85a4a02d5616f1e8b

broken w/ flumelob-offset

austinfrey committed on 11/1/2018, 4:09:49 AM
Parent: e28105f1d92f3398e08fa1cfbf376539f6bc37ba

Files changed

.gitignorechanged
stores/ledger.jschanged
.gitignoreView
@@ -3,5 +3,6 @@
33 coverage/
44 dist/
55 tmp/
66 npm-debug.log*
7-.DS_Store
7 +.DS_Store
8 +.test.db
stores/ledger.jsView
@@ -1,14 +1,15 @@
11 const Flume = require('flumedb')
22 const Reduce = require('flumeview-reduce')
3-const FlumeLog = require('flumelog-memory')
3 +//const FlumeLog = require('flumelog-memory')
4 +const FlumeLog = require('flumelog-offset')
45 const {pull, drain} = require('pull-stream')
56
67 function ledger (state, emitter) {
78 state.accounts = {}
89 state.entries = []
910
10- const db = Flume(FlumeLog())
11 + const db = Flume(FlumeLog('.test.db'))
1112 .use('entries', Reduce(1, entriesReducer, null, null, state.entries))
1213 .use('accounts', Reduce(1, accountReducer, null, null, state.accounts))
1314 .use('balances', Reduce(1, accountBalanceReducer, null, null, state.accounts))
1415
@@ -22,18 +23,21 @@
2223 emitter.on('entries', onEvent)
2324 }
2425
2526 function onEvent (data) {
27 + console.log('event')
2628 db.append(data, (err, seq) => {
2729 if (err) throw err
30 + console.log('append')
2831 emitter.emit(state.events.RENDER)
2932 })
3033 }
3134
3235 emitter.on('DOMContentLoaded', onLoad)
3336 }
3437
3538 function accountBalanceReducer (acc, item) {
39 + console.log('balance')
3640 if (item.type !== 'entries') return acc
3741 const {msg} = item
3842
3943 acc[msg.debit].debit += msg.amount
@@ -41,16 +45,19 @@
4145 return acc
4246 }
4347
4448 function entriesReducer (acc, item) {
49 + console.log('entries')
4550 if (item.type !== 'entries') return acc
4651 acc.push(item)
4752 return acc
4853 }
4954
5055 function accountReducer (acc, item) { // TODO account for account creation of existing account
56 + console.log('account')
5157 if (item.type !== 'accounts') return acc
5258 const { msg } = item
59 + console.log(acc, item)
5360
5461 if (!acc[msg.name]) {
5562 acc[msg.name] = msg
5663 return acc

Built with git-ssb-web