You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/articles/data_comps_using_sync.md
+28-29Lines changed: 28 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,60 +16,59 @@ a `url` property is also exposed and can be used to set the base or non-changing
16
16
17
17
### Param configuration
18
18
19
-
Sync's configuration is divided into 2 sets of operations: input and output.
20
-
Input params are used for `GET` requests. Output params are used for `POST`, `PUT`, and `DELETE` requests.
19
+
Sync accepts configuration via tags corresponding to HTTP methods: `<get>`, `<post>`, `<put>`, and `<delete>`. Params can then be passed to Sync as DOM children of those nodes.
21
20
22
21
Params were designed to give the developer full flexibility over crafting the request arguments. With this in mind the param options were divided into:
23
22
24
-
* queryParam -- name value pair objects used to generate the queryString
25
-
* urlParam -- name only strings concatenated with '/' to generate a URL
26
-
* headers -- name value pairs used to send additional metadata (CSRF, etc) to the webserver
23
+
* queryParam — name value pair objects used to generate the queryString
24
+
* urlParam — name only strings concatenated with '/' to generate a URL
25
+
* headers — name value pairs used to send additional metadata (CSRF, etc) to the webserver
27
26
28
-
The 'direction' of input or output is relative to the component itself, so when you are pulling data from the server via a get, we consider that 'input' to the component, and the reverse is true for saving/deletion operations.
29
-
30
-
### Input param example
27
+
### GET example
31
28
32
29
```html
33
30
<mm-syncendpoint="http://example.com">
34
-
<input-params>
31
+
<get>
35
32
<queryParamname="q"value="123"/>
36
33
<urlParam>123</urlParam>
37
34
<headername="X-Some-Header">HeaderValue</header>
38
-
</input-params>
35
+
</get>
39
36
</mm-sync>
40
37
```
41
38
42
-
This will generate a URL for the request of `http://example.com/123/?q=123` and it will send an X-Some-Header: HeaderValue to the server with the request. Note that it is possible to either use a value attribute or to just place the value inside the body of a named node. These formats may be used interchangeably.
39
+
This will generate a URL for the request of `http://example.com/123/?q=123` and it will send an X-Some-Header: HeaderValue to the server with the request. Note that it is possible to either use a value attribute or to just place the value inside the textContent of a named node. These formats may be used interchangeably.
Note that we use the urlParam twice--this may be done for any set of params N number of times as appropriate. Params are parsed top down for API's where the order matters.
52
+
Note that we use the urlParam twice — this may be done for any set of params _N_ number of times as appropriate. Params are parsed top down for API's where the order matters.
56
53
57
-
It is also possible to set both input and output params on the same element to configure it for general I/O by adding both sections at the same level:
54
+
It is also possible to pass multiple sets of params to the same element to configure it for general I/O by adding sections at the same level:
58
55
59
56
```html
60
57
<mm-sync>
61
-
<input-params></input-params>
62
-
<output-params></output-params>
58
+
<get></get>
59
+
<post></post>
60
+
<put></put>
61
+
<delete></delete>
63
62
</mm-sync>
64
63
```
65
64
66
65
## Working with 2-way binding
67
66
68
-
To support 2-way binding in a scenario using mm-sync we have created the `auto`param. Auto tells mm-sync to respond automatically to data or param changes and make additional requests to sync the data back to the server. Auto may be set via JS or via HTML as an attribute. Auto has 3 possible values:
67
+
To support 2-way binding in a scenario using mm-sync we have created the `auto`property. Auto tells mm-sync to respond automatically to data or param changes and make additional requests to sync the data back to the server. Auto may be set via JS or via HTML as an attribute. Auto has 3 possible values:
69
68
70
-
* true `boolean` -- bidirectional sync input/output for any changes
71
-
* load `string`-- only sync data in from server when input params change
72
-
* save `string` -- only sync data in from the server when the data property detects a change-- note that due to polymer 1.0 data binding limitations you must manually tell polymer that the data has changed using `set`
69
+
* true `boolean` — bidirectional sync input/output for any changes
70
+
* load `string` — only sync data in from server when input params change
71
+
* save `string` — only sync data in from the server when the data property detects a change — note that due to Polymer 1.0 data binding limitations you must manually tell Polymer that the data has changed using `set`
73
72
74
73
```javascript
75
74
var sync =document.querySelector("mm-sync");
@@ -92,19 +91,19 @@ The following is an example of the simple input scenario using a self binding te
92
91
Now bind this to a sync components params from our earlier example:
93
92
94
93
```html
95
-
<templateis="auto-binding">
94
+
<templateis="dom-bind">
96
95
<mm-inputvalue="{{search}}"/>
97
96
<mm-syncendpoint="http://example.com"auto="true">
98
-
<input-params>
97
+
<get>
99
98
<queryParamname="q"value="{{search}}"/>
100
99
<urlParam>123</urlParam>
101
100
<headername="X-Some-Header">HeaderValue</header>
102
-
</input-params>
101
+
</get>
103
102
</mm-sync>
104
103
</template>
105
104
```
106
105
107
-
When the lightDOM queryParam values are changed via 2-way binding, the sync component will pick this up and trigger the requisite `GET` calls to retrieve this query from the server. Note that this input is automatically debounced against keyboard input. If necessary you may vary this timing via the `autoDebounce` property. The default is 200ms.
106
+
When the light DOM queryParam values are changed via 2-way binding, the sync component will pick this up and trigger the requisite `GET` calls to retrieve this query from the server. Note that this input is automatically debounced against keyboard input. If necessary you may vary this timing via the `autoDebounce` property. The default is 200ms.
108
107
109
108
### 2-way binding on the response
110
109
@@ -114,16 +113,16 @@ Unfortunately this example does not provide any feedback to the user, but it is
0 commit comments