@@ -24,28 +24,23 @@ module.exports = class Adaptor {
2424 * @param {Object } options
2525 */
2626 createConnection ( options ) {
27- let merged = { ... STD , ... options } ;
28- const url = new URL ( `${ merged . protocol } ://${ merged . hostname } ` ) ;
29- url . port = merged . port ;
30- url . username = merged . username ;
31- url . password = merged . password ;
27+
28+ const url = new URL ( `${ options . protocol } ://${ options . hostname } ` ) ;
29+ url . port = options . port ;
30+ url . username = options . username ;
31+ url . password = options . password ;
3232 this . connection = nano ( url . toString ( ) ) ;
3333 }
3434
3535 /**
3636 * @method connect
3737 * @param {Object } options
3838 */
39- async connect ( options ) {
40- this . createConnection ( options ) ;
41- const { database} = options ;
39+ connect ( options ) {
40+ let merged = { ...STD , ...options } ;
41+ this . createConnection ( merged ) ;
42+ const { database} = merged ;
4243 this . db = this . connection . db . use ( database ) ;
43- this . subscribe ( options . seq ) ;
44- // for cold start
45- const docs = await this . looseTasks ( ) ;
46- docs . forEach ( ( doc ) => {
47- this . onChange ( this . formatDoc ( doc ) ) ;
48- } ) ;
4944 }
5045
5146 /**
@@ -72,9 +67,14 @@ module.exports = class Adaptor {
7267
7368 /**
7469 * @method subscribe
75- * @param {Number } seq
7670 */
77- subscribe ( seq ) {
71+ async subscribe ( ) {
72+ // for cold start
73+ const docs = await this . looseTasks ( ) ;
74+ docs . forEach ( ( doc ) => {
75+ this . onChange ( this . formatDoc ( doc ) ) ;
76+ } ) ;
77+
7878 const name = this . name ;
7979 this . feed = this . db . follow ( {
8080 include_docs : true ,
@@ -115,6 +115,10 @@ module.exports = class Adaptor {
115115 return docs ;
116116 }
117117
118+ create ( task ) {
119+ return this . db . insert ( task ) ;
120+ }
121+
118122 /**
119123 * @method update
120124 * @param {Object } task
0 commit comments