-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.rtf
38 lines (38 loc) · 2.11 KB
/
2.rtf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{\rtf1\ansi\uc0\deff0{\fonttbl{\f0\fmodern\fprq1\fcharset0;}}{\colortbl;\red23\green117\blue0;\red99\green56\blue32;\red28\green1\blue206;\red196\green26\blue22;\red35\green0\blue206;\red0\green0\blue0;\red169\green13\blue145;\red131\green108\blue40;\red63\green110\blue117;\red91\green38\blue154;}\f0 {\cf7 const} {\cf6 kappa} {\cf6 =} {\cf6 require}({\cf4 'kappa-core'});\par
{\cf7 const} {\cf6 ram} {\cf6 =} {\cf6 require}({\cf4 'random-access-memory'});\par
{\cf7 const} {\cf6 recordView} {\cf6 =} {\cf6 require}({\cf4 './record-view'});\par
{\cf7 const} {\cf6 level} {\cf6 =} {\cf6 require}({\cf4 'level-mem'});\par
\par
{\cf1 // Create a kappa instance. \par
}{\cf7 const} {\cf6 core} {\cf6 =} {\cf6 kappa}({\cf6 ram}, \{ {\cf6 valueEncoding}{\cf6 :} {\cf4 "json"} \});\par
{\cf6 core}.{\cf6 use}({\cf4 'records'}, {\cf6 recordView}({\cf6 level}(\{ {\cf6 valueEncoding}{\cf6 :} {\cf4 "json"} \})))\par
{\cf1 // Get a write feed\par
}{\cf6 core}.{\cf6 writer}({\cf4 "local"}, {\cf7 async} {\cf7 function} ({\cf6 err}, {\cf6 feed}) \{\par
{\cf1 // Add a todo to our log\par
} {\cf7 const} {\cf6 todo1} {\cf6 =} \{ {\cf6 id}{\cf6 :} {\cf3 1}, {\cf6 text}{\cf6 :} {\cf4 "Do the thing!"}, {\cf6 done}{\cf6 :} {\cf7 false} \};\par
{\cf7 const} {\cf6 todo2} {\cf6 =} \{ {\cf6 id}{\cf6 :} {\cf3 2}, {\cf6 text}{\cf6 :} {\cf4 "Do more!"}, {\cf6 done}{\cf6 :} {\cf7 false} \};\par
{\cf6 feed}.{\cf6 append}(\{\par
{\cf6 type}{\cf6 :} {\cf4 'put'},\par
...{\cf6 todo1}\par
\});\par
{\cf6 feed}.{\cf6 append}(\{\par
{\cf6 type}{\cf6 :} {\cf4 'put'},\par
...{\cf6 todo2}\par
\});\par
{\cf6 feed}.{\cf6 append}(\{\par
{\cf6 type}{\cf6 :} {\cf4 'del'},\par
...{\cf6 todo1}\par
\});\par
{\cf6 feed}.{\cf6 append}(\{\par
{\cf6 type}{\cf6 :} {\cf4 'put'},\par
...{\cf6 todo2},\par
{\cf6 done}{\cf6 :} {\cf7 true}\par
\});\par
\});\par
\par
{\cf6 core}.{\cf6 ready}([], {\cf7 function} () \{\par
{\cf6 core}.{\cf6 api}.{\cf6 records}.{\cf6 all}({\cf7 function} ({\cf6 data}) \{\par
{\cf6 console}.{\cf6 log}({\cf6 data});\par
\})\par
\})\par
}