Files: ca718f616a051e93adeb22faa3fc06646f667973 / profiles / app.js
685 bytesRaw
1 | const { assign } = Object |
2 | const async = require('pull-async') |
3 | |
4 | const { SET_ONE, FETCH_ONE, setOne } = require('./actions') |
5 | |
6 | module.exports = ProfilesApp |
7 | |
8 | function ProfilesApp (config) { |
9 | return { |
10 | init: () => ({ |
11 | model: {}, |
12 | }), |
13 | update: { |
14 | [SET_ONE]: (model, profile) => ({ |
15 | model: assign({}, model, { [profile.id]: profile }) |
16 | }) |
17 | }, |
18 | run: { |
19 | [FETCH_ONE]: (id) => { |
20 | return async(cb => { |
21 | xhr({ |
22 | url: `/api/profiles/${profile}`, |
23 | json: true |
24 | }, (err, resp, { body } = {}) => { |
25 | if (err) return cb(err) |
26 | cb(null, setOne(body)) |
27 | }) |
28 | }) |
29 | }, |
30 | } |
31 | } |
32 | } |
33 |
Built with git-ssb-web