Skip to content

Commit b179375

Browse files
committed
Update documentation for insertOnce
1 parent 66b2a78 commit b179375

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

source/includes/_methods.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ After creating the callback object, you must then return it for the API to creat
115115
// Initialize an instance of the API
116116
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
117117

118-
// Receive a notification whenever vehicle data is updated on the page (or a new page is loaded).
118+
// Receive a notification each time vehicle data is updated on the page (or a new page is loaded).
119119
API.subscribe('vehicle-data-updated-v1', function(ev) {
120120

121121
// Collect the VIN for each vehicle on the page in an array.
@@ -219,7 +219,9 @@ The insert method allows you to append markup to specific locations on some page
219219

220220
When activated, `API.insert` will call the callback function you define with the `elem` and `meta` parameters. It will call this for each relevant location on the page. For example, if you specify `vehicle-media` as the location and you are viewing a search results page with 30 vehicles, the callback function you define on `API.insert` will be called 30 times, once per vehicle, with the relevant location and vehicle data in the payload.
221221

222-
This acts as an event subscription, so as the application displays new vehicles dynamically (a single page application), new events are fired and your callback is automatically called for each of those new items. This works well for a basic use case where you want to place content on every item having the target location, or every item matching specific criteria available to you in the callback payload. If you need to execute additional code before determining if you wish to insert content, such as calling an external service, you should use the `insertOnce` method instead.
222+
This acts as an event subscription, so as the application displays new vehicles dynamically (a single page application), new events are fired and your callback is immediately called for each of those new items. This works well for a basic use case where you want to place content on every item having the target location, or every item matching specific criteria available to you in the callback payload.
223+
224+
If you need to execute additional code before determining if you wish to insert content, such as calling an external service, you should use the `insertOnce` method instead in combination with the `vehicle-data-updated-v1` event as shown in the example here.
223225

224226
## API.insertOnce(name, callback(elem, meta))
225227

@@ -228,9 +230,13 @@ This acts as an event subscription, so as the application displays new vehicles
228230
```javascript
229231
(function(WIAPI) {
230232
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
231-
API.insertOnce('location-name', function(elem, meta) {
232-
API.log(elem); // The DOM element where markup may be inserted.
233-
API.log(meta); // The payload object for the current insertion point.
233+
// Receive a notification each time vehicle data is updated on the page (or a new page is loaded).
234+
API.subscribe('vehicle-data-updated-v1', function(ev) {
235+
// Insert content into each vehicle location now present on the page.
236+
API.insertOnce('location-name', function(elem, meta) {
237+
API.log(elem); // The DOM element where markup may be inserted.
238+
API.log(meta); // The payload object for the current insertion point.
239+
});
234240
});
235241
})(window.DDC.API);
236242
```
@@ -243,7 +249,7 @@ This acts as an event subscription, so as the application displays new vehicles
243249
// Initialize an instance of the API
244250
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
245251

246-
// Receive a notification whenever vehicle data is updated on the page (or a new page is loaded).
252+
// Receive a notification each time vehicle data is updated on the page (or a new page is loaded).
247253
API.subscribe('vehicle-data-updated-v1', function(ev) {
248254

249255
// Collect the VIN for each vehicle on the page in an array.

0 commit comments

Comments
 (0)