|
2 | 2 |
|
3 | 3 | #### Constructor
|
4 | 4 |
|
5 |
| -* `const selector = new Selector(sources, parserCallback(sourcesResults[, currentQuery]), [defaultValue])` |
6 |
| - * Arguments |
7 |
| - * sources - `<source object or Array of sources objects>` |
8 |
| - * source object - `<source instance, or customSourceReader object>` |
9 |
| - * source instance - `<instance of an Origin or Selector>` Origin or Selector to read. |
10 |
| - * customSourceReader - `<Object>` with next properties: |
11 |
| - * `source`: `<instance of an Origin or Selector>` Origin or Selector to read. |
12 |
| - * `query`: `<Function>` `query: (currentQuery[, previousSourcesResults])`. Query callback. |
13 |
| - * Arguments: |
14 |
| - * currentQuery - `<Any>` Selector current query. |
15 |
| - * previousSourcesResults - `<Array of Any>` Array containing results of all previously fetched sources in series. |
16 |
| - * Returns: |
17 |
| - * `<Any>` Result of this callback will be passed as `query` to the source. |
18 |
| - * `catch`: `<Function>` `catch: (error[, currentQuery])`. |
19 |
| - * Arguments: |
20 |
| - * error - `<Error>` Error thrown by the read method of the source. |
21 |
| - * currentQuery - `<Any>` Selector current query. |
22 |
| - * Returns: |
23 |
| - * `<Error>` - Source will throw this error. |
24 |
| - * `<Any>` - Source will return this value instead of error. |
25 |
| - * `<source instance>` - The `read` method of the returned source instance will be called, and returned result will be assigned as value of the current source (Allows to switch to another source if first returns an error) |
26 |
| - * Array of source objects - `<Array of <source object>>` Provided sources will be fetched in parallel. |
27 |
| - * parserCallback - `<Function>` |
28 |
| - * Arguments: |
29 |
| - * sourcesResults - `<Any>` - Results returned by the `read` method of the sources. |
30 |
| - * currentQuery - `<Any>` Selector current query. |
31 |
| - * Returns: |
32 |
| - * Result data - `<Any>` |
33 |
| - * `<Promise>` - The result of the returned Promise will be returned as result data. |
34 |
| - * `<source instance>` - If another source instance is returned, it will be called with same method and data than Selector was. |
35 |
| - * defaultValue - `<Any>` Default value to return until real data is returned. |
| 5 | +* `const selector = new Selector(source, source, parserCallback(sourcesResults[, currentQuery]), [options])` |
| 6 | + * Arguments |
| 7 | + * sources - `<source object or Array of sources objects>` |
| 8 | + * source object - `<source instance, or customSourceReader object>` |
| 9 | + * source instance - `<instance of an Origin or Selector>` Origin or Selector to read. |
| 10 | + * customSourceReader - `<Object>` with next properties: |
| 11 | + * `source`: `<instance of an Origin or Selector>` Origin or Selector to read. |
| 12 | + * `query`: `<Function>` `query: (currentQuery[, previousSourcesResults])`. Query callback. |
| 13 | + * Arguments: |
| 14 | + * currentQuery - `<Any>` Selector current query. |
| 15 | + * previousSourcesResults - `<Array of Any>` Array containing results of all previously fetched sources in series. |
| 16 | + * Returns: |
| 17 | + * `<Any>` Result of this callback will be passed as `query` to the source. |
| 18 | + * `catch`: `<Function>` `catch: (error[, currentQuery])`. |
| 19 | + * Arguments: |
| 20 | + * error - `<Error>` Error thrown by the read method of the source. |
| 21 | + * currentQuery - `<Any>` Selector current query. |
| 22 | + * Returns: |
| 23 | + * `<Error>` - Source will throw this error. |
| 24 | + * `<Any>` - Source will return this value instead of error. |
| 25 | + * `<source instance>` - The `read` method of the returned source instance will be called, and returned result will be assigned as value of the current source (Allows to switch to another source if first returns an error) |
| 26 | + * Array of source objects - `<Array of <source object>>` Provided sources will be fetched in parallel. |
| 27 | + * parserCallback - `<Function>` |
| 28 | + * Arguments: |
| 29 | + * sourcesResults - `<Any>` - Results returned by the `read` method of the sources. |
| 30 | + * currentQuery - `<Any>` Selector current query. |
| 31 | + * Returns: |
| 32 | + * Result data - `<Any>` |
| 33 | + * `<Promise>` - The result of the returned Promise will be returned as result data. |
| 34 | + * `<source instance>` - If another source instance is returned, it will be called with same method and data than Selector was. |
| 35 | + * options - `<Object>` |
| 36 | + * defaultValue - `<Any>` Default value to return until real data is returned. |
| 37 | + * uuid - `<String>` Custom uuid to be defined as selector "_id" |
36 | 38 |
|
37 | 39 | #### Instance
|
38 | 40 |
|
39 | 41 | * read `selector.read()`
|
40 |
| - * Statics: |
41 |
| - * error - `<Error>` If read method returns an error, it will be accessible at this property. |
42 |
| - * loading - `<Boolean>` Will be true while Selector read is in progress. |
43 |
| - * value - `<Any>` Value returned by `read` method. |
44 |
| - * Returns |
45 |
| - * `<Any>` - Result of the parser function. |
| 42 | + * Statics: |
| 43 | + * error - `<Error>` If read method returns an error, it will be accessible at this property. |
| 44 | + * loading - `<Boolean>` Will be true while Selector read is in progress. |
| 45 | + * value - `<Any>` Value returned by `read` method. |
| 46 | + * Returns |
| 47 | + * `<Any>` - Result of the parser function. |
46 | 48 | * create, update, delete `selector.create(data)` These methods can be used only when Selector returns another source.
|
47 |
| - * Statics: |
48 |
| - * error - `<Error>` If read method returns an error, it will be accessible at this property. |
49 |
| - * loading - `<Boolean>` Will be true while Selector read is in progress. |
50 |
| - * value - `<Any>` Value returned by `read` method. |
51 |
| - * Arguments |
52 |
| - * data - `<Any>` Data that will be passed to the correspondant create, update or delete method of the returned source. |
53 |
| - * Returns |
54 |
| - * `<Any>` - Result of the correspondant method of returned source. |
| 49 | + * Statics: |
| 50 | + * error - `<Error>` If read method returns an error, it will be accessible at this property. |
| 51 | + * loading - `<Boolean>` Will be true while Selector read is in progress. |
| 52 | + * value - `<Any>` Value returned by `read` method. |
| 53 | + * Arguments |
| 54 | + * data - `<Any>` Data that will be passed to the correspondant create, update or delete method of the returned source. |
| 55 | + * Returns |
| 56 | + * `<Any>` - Result of the correspondant method of returned source. |
55 | 57 | * clean `selector.clean([query])`
|
56 |
| - * Arguments |
57 |
| - * query - `<Any>` Any object, string, array etc. for quering the source. |
58 |
| - * Returns |
59 |
| - * `<undefined>` - Selector instance cache corresponding to the provided query will be cleaned. |
| 58 | + * Arguments |
| 59 | + * query - `<Any>` Any object, string, array etc. for quering the source. |
| 60 | + * Returns |
| 61 | + * `<undefined>` - Selector instance cache corresponding to the provided query will be cleaned. |
60 | 62 | * query `selector.query([query])`
|
61 |
| - * Arguments |
62 |
| - * query - `<Any>` Any object, string, array etc. for quering the source. |
63 |
| - * Returns |
64 |
| - * `<selector instance>` - Will return a selector instance unique for the query provided. Returned instances will be the same if query is the same. |
| 63 | + * Arguments |
| 64 | + * query - `<Any>` Any object, string, array etc. for quering the source. |
| 65 | + * Returns |
| 66 | + * `<selector instance>` - Will return a selector instance unique for the query provided. Returned instances will be the same if query is the same. |
65 | 67 | * addCustomQueries `selector.addCustomQueries(customQueryObject)`
|
66 |
| - * Aliases |
67 |
| - * addCustomQuery `selector.addCustomQuery({ queryName: queryCallback(query)})` |
68 |
| - * Arguments |
69 |
| - * customQueryObject - `<Object>` containing properties: |
70 |
| - * [key] - `<String>` Key will be used as name of the new selector method that will execute the custom query. |
71 |
| - * queryCallback - `<Function>` |
72 |
| - * Arguments |
73 |
| - * query - `<Any>` Query provided by the user when using custom query method. |
74 |
| - * Returns |
75 |
| - * currentQuery - `<Any>` Query that will be used as current query, and passed to the CRUD methods when executed. |
| 68 | + * Aliases |
| 69 | + * addCustomQuery `selector.addCustomQuery({ queryName: queryCallback(query)})` |
| 70 | + * Arguments |
| 71 | + * customQueryObject - `<Object>` containing properties: |
| 72 | + * [key] - `<String>` Key will be used as name of the new selector method that will execute the custom query. |
| 73 | + * queryCallback - `<Function>` |
| 74 | + * Arguments |
| 75 | + * query - `<Any>` Query provided by the user when using custom query method. |
| 76 | + * Returns |
| 77 | + * currentQuery - `<Any>` Query that will be used as current query, and passed to the CRUD methods when executed. |
0 commit comments