git ssb

0+

Zach! / dat-zine-library



Tree: 89658f9e88208096af0770fc6f691ff668a73c0b

Files: 89658f9e88208096af0770fc6f691ff668a73c0b / volunteers / displayBranchInfo.js

794 bytesRaw
1const smarkt = require('smarkt')
2
3const formHandler = require('./formHandler')
4
5var archive = new DatArchive(window.location)
6
7function store (state, emitter) {
8 state.branch = {}
9 emitter.on('DOMContentLoaded', function () {
10 mapInfoToState(state, emitter)
11 })
12
13 emitter.on('branch updated', function (form) {
14 var infoAsObj = formHandler.handle(form)
15 var infoAsTxt = smarkt.stringify(infoAsObj)
16
17 state.branch = infoAsObj
18 archive.writeFile('branch/info.txt', infoAsTxt)
19 .then(emitter.emit('pushState'))
20 })
21
22 function mapInfoToState (state, emitter) {
23 archive.readFile('branch/info.txt')
24 .then(info => {
25 var infoAsObj = smarkt.parse(info)
26 state.branch = infoAsObj
27 emitter.emit('pushState')
28 })
29 }
30}
31
32module.exports = store
33

Built with git-ssb-web