Skip to content

Commit 0f8b8b8

Browse files
author
Christian Lilley
committed
Revised commenting, sequencing
1 parent 4c8a51f commit 0f8b8b8

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ <h1>Promises Demo App</h1>
3535
</header>
3636
<section id="mainContent" role=main>
3737

38+
3839
<div class="btn-group">
39-
<button class="btn" onclick="chainSimplePromise('Huh. It works.')">Simple, Immediate Resolution</button>
40+
<button class="btn" onclick="delayOld(1500)">DelayOld</button>
41+
<button class="btn" onclick="delayNew(1500).then(valueLogger)">DelayNew</button>
4042
</div>
4143

4244
<div class="btn-group">
43-
<button class="btn" onclick="delayOld(1500)">DelayOld</button>
44-
<button class="btn" onclick="delayNew(1500).then(valueLogger)">DelayNew</button>
45+
<button class="btn" onclick="chainSimplePromise('Huh. It works.')">Simple, Immediate Resolution</button>
4546
</div>
4647

4748
<div class="btn-group">
4849
<button class="btn" onclick="createDeferred()">Create New Deferred</button>
49-
<button class="btn" onclick="inspectDeferred()">Inspect Deferred</button>
50+
<button class="btn" onclick="inspectDeferred()">Inspect Promise</button>
5051
<button class="btn" onclick="isDeferredResolved()">Deferred is Fulfilled?</button>
5152
<button class="btn" onclick="addHandlerToDeferred()">Add a .then()</button>
5253
<button class="btn" onclick="resolveDeferred()">Resolve Deferred!</button>

js/app.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function delayNew(ms) {
8484
var delayMessage = 'Delay Resolved after ' + ms + ' milliseconds.';
8585

8686
// Your code follows...
87-
// IMPLEMENT
87+
// IMPLEMENT #1
8888

8989

9090

@@ -97,28 +97,28 @@ function simpleWrapper(value) {
9797
// Creating Promises for simple values or synchronous function output
9898

9999
// We just wrap the basic value and immediately return the resolved promise.
100-
// IMPLEMENT
100+
// IMPLEMENT #2
101101

102102
}
103103

104104
function chainSimplePromise(value) {
105105
// Make a promise using our wrapper function, then look at what's inside.
106-
// IMPLEMENT
106+
// IMPLEMENT #3
107107

108108
}
109109

110110
function stripOutMainContent(wholePage) {
111111
// First we perform some basic DOM stuff to get the content:
112112
var content = $(wholePage).find('section').html()
113113
// But now, we need to wrap this content in a promise, so we can continue a chain...
114-
// IMPLEMENT
114+
// IMPLEMENT #11
115115

116116
}
117117

118118
function writeArticleToDOM(articleText) {
119119
$('article').html(articleText);
120120
// and, just as good form, return a promise to the end of the chain, containing articleText, so we can see the output:
121-
// IMPLEMENT
121+
// IMPLEMENT #12
122122

123123
}
124124

@@ -132,12 +132,12 @@ function doMoreStuff() {
132132
// Now, take that promise, stripOutMainContent and then writeArticleToDOM
133133
// NOTE: stripOutMainContent still needs to be implemented!!!
134134
// (Wat? JQuery promises are weird... What do we do?)
135-
// IMPLEMENT:
135+
// IMPLEMENT #9
136136
// compoundXHR =
137137

138138
// Now, because this is a network operation, it can fail for all kinds of reasons.
139139
// Handle errors with the provided 'errorLogger' function.
140-
// IMPLEMENT:
140+
// IMPLEMENT #10
141141

142142
// NETWORK OPERATION ENDS
143143

@@ -148,20 +148,20 @@ function doMoreStuff() {
148148
// IMPLEMENT
149149
// simplePromise =
150150
// Now, access this promise and just log the content:
151-
// IMPLEMENT
151+
// IMPLEMENT #6
152152

153153
// SIMPLE VALUE PROMISE ENDS
154154

155155

156156
// TIMEOUT PROMISE
157157
// Create a new promise based on a Timeout of 2500ms, using our promise-generating delayNew Function;
158-
// IMPLEMENT
158+
// IMPLEMENT #7
159159
// delayPromise =
160160
/* ( Side-note: Alternately, we could actually use Q's convenience method for timeouts, which returns a promise:
161161
ex.: delayPromise = Q.delay(2500) ) */
162162

163163
// Now, access this delayPromise and just log the content:
164-
// IMPLEMENT
164+
// IMPLEMENT #8
165165

166166
// TIMEOUT PROMISE ENDS
167167

@@ -170,9 +170,10 @@ function doMoreStuff() {
170170
// The .all() method returns a new, aggregated, promise.
171171
// It's resolved when an entire array of promises are each resolved.
172172
// We want an aggregate promise composed of simplePromise, compoundXHR & delayPromise
173-
// Then, log that promise
174-
// Then, run writeToDOMAgain
175-
// IMPLEMENT
173+
// Then, log that promise
174+
// Then, run writeToDOMAgain
175+
// IMPLEMENT #13 (depends on #11-#12)
176+
176177
}
177178

178179

@@ -182,17 +183,17 @@ function doMoreStuff() {
182183
// IMPLEMENT
183184
// docPromise =
184185
$('document').ready(function(){
185-
console.log('Doc Ready. No other functions ready yet.') // disable me when more interesting things are happening
186+
// console.log('Doc Ready. No other functions ready yet.') // disable me when more interesting things are happening
186187
var readyMessage = 'Document is ready now. Go Ahead and do more promise stuff!';
187188
// This is where you should resolve the docPromise, with the message above...
188-
// IMPLEMENT
189+
// IMPLEMENT #4
189190

190191
})
191192
// Create handlers for the docPromise that:
192-
// 1. Just shows its value
193+
// 1. Just shows its value
193194
// 2. Uses the 'writeToDOM' function to print it out
194195
// 3. continues our control-flow with doMoreStuff !
195196

196-
// IMPLEMENT
197+
// IMPLEMENT #5
197198

198199

0 commit comments

Comments
 (0)