This repository has been archived by the owner on Oct 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
90 lines (73 loc) · 2.08 KB
/
index.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>iron-ajax-sequence</title>
<script src="../webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="../polymer/polymer.html"/>
</head>
<body>
<iron-ajax-sequence></iron-ajax-sequence>
<dom-module id="iron-ajax-sequence">
<link rel="import" href="../iron-ajax/iron-ajax.html"/>
<template>
<iron-ajax id="ajax1"
url="one.json"
on-response="handleOneResponse"></iron-ajax>
<iron-ajax id="ajax2"
url="two.json"
on-response="handleTwoResponse"></iron-ajax>
<button id="btn">Go</button>
<template is="dom-if" if="[[recursed]]">
<h3>Recursion detected</h3>
</template>
<ol>
<template is="dom-repeat" items="[[events]]" as="event">
<li>[[event]]</li>
</template>
</ol>
</template>
<script>
Polymer({
is: 'iron-ajax-sequence',
properties: {
events: {
type: Array,
value: function () {
return [];
}
}
},
ready: function () {
this.$.btn.addEventListener('click', function () {
this.startAjax();
}.bind(this));
// To avoid crapping out the browser
this.interval = setInterval(function () {
if (this.events.length > 10) {
this.push('events', 'recursed?!');
this.set('recursed', true);
clearInterval(this.interval);
}
}.bind(this), 200);
},
startAjax: function () {
this.push('events', 'starting ajax1');
this.$.ajax1.generateRequest();
},
handleOneResponse: function (e) {
if (this.recursed) {
return;
}
this.push('events', 'response handler of ajax1');
this.push('events', 'starting ajax2');
this.$.ajax2.generateRequest();
},
handleTwoResponse: function (e) {
this.push('events', 'response handler of ajax2 (this should only appear once)');
}
});
</script>
</dom-module>
</body>
</html>