Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rsvp.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
rsvp.js
Commits
8a24804f
Commit
8a24804f
authored
Mar 17, 2013
by
Yehuda Katz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RSVP.hash
parent
257996c1
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
279 additions
and
54 deletions
+279
-54
browser/rsvp.amd.js
browser/rsvp.amd.js
+6
-4
browser/rsvp.js
browser/rsvp.js
+68
-19
browser/rsvp.min.js
browser/rsvp.min.js
+1
-1
browser/rsvp/all.amd.js
browser/rsvp/all.amd.js
+8
-15
browser/rsvp/hash.amd.js
browser/rsvp/hash.amd.js
+53
-0
lib/rsvp.js
lib/rsvp.js
+2
-1
lib/rsvp/all.js
lib/rsvp/all.js
+7
-14
lib/rsvp/hash.js
lib/rsvp/hash.js
+48
-0
tests/extension-tests.js
tests/extension-tests.js
+86
-0
No files found.
browser/rsvp.amd.js
View file @
8a24804f
define
(
[
"
rsvp/events
"
,
"
rsvp/promise
"
,
"
rsvp/node
"
,
"
rsvp/all
"
,
"
rsvp/defer
"
,
"
rsvp/config
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__dependency3__
,
__dependency4__
,
__dependency5__
,
__dependency6__
,
__exports__
)
{
[
"
rsvp/events
"
,
"
rsvp/promise
"
,
"
rsvp/node
"
,
"
rsvp/all
"
,
"
rsvp/
hash
"
,
"
rsvp/
defer
"
,
"
rsvp/config
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__dependency3__
,
__dependency4__
,
__dependency5__
,
__dependency6__
,
__
dependency7__
,
__
exports__
)
{
"
use strict
"
;
var
EventTarget
=
__dependency1__
.
EventTarget
;
var
Promise
=
__dependency2__
.
Promise
;
var
denodeify
=
__dependency3__
.
denodeify
;
var
all
=
__dependency4__
.
all
;
var
defer
=
__dependency5__
.
defer
;
var
config
=
__dependency6__
.
config
;
var
hash
=
__dependency5__
.
hash
;
var
defer
=
__dependency6__
.
defer
;
var
config
=
__dependency7__
.
config
;
function
configure
(
name
,
value
)
{
config
[
name
]
=
value
;
...
...
@@ -16,6 +17,7 @@ define(
__exports__
.
Promise
=
Promise
;
__exports__
.
EventTarget
=
EventTarget
;
__exports__
.
all
=
all
;
__exports__
.
hash
=
hash
;
__exports__
.
defer
=
defer
;
__exports__
.
denodeify
=
denodeify
;
__exports__
.
configure
=
configure
;
...
...
browser/rsvp.js
View file @
8a24804f
...
...
@@ -32,23 +32,16 @@ var define, requireModule;
})();
define
(
"
rsvp/all
"
,
[
"
rsvp/
promise
"
,
"
exports
"
],
[
"
rsvp/
defer
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
var
defer
=
__dependency1__
.
defer
;
function
all
(
promises
)
{
var
i
,
results
=
[],
resolve
,
reject
;
var
allPromise
=
new
Promise
(
function
(
allResolver
,
allRejecter
)
{
resolve
=
allResolver
;
reject
=
allRejecter
;
});
var
remaining
=
promises
.
length
;
var
results
=
[],
deferred
=
defer
(),
remaining
=
promises
.
length
;
if
(
remaining
===
0
)
{
resolve
([]);
deferred
.
resolve
([]);
}
var
resolver
=
function
(
index
)
{
...
...
@@ -60,22 +53,22 @@ define("rsvp/all",
var
resolveAll
=
function
(
index
,
value
)
{
results
[
index
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
deferred
.
resolve
(
results
);
}
};
var
rejectAll
=
function
(
error
)
{
reject
(
error
);
deferred
.
reject
(
error
);
};
for
(
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
if
(
promises
[
i
]
&&
typeof
promises
[
i
].
then
===
'
function
'
)
{
promises
[
i
].
then
(
resolver
(
i
),
rejectAll
);
}
else
{
resolveAll
(
i
,
promises
[
i
]);
}
}
return
allP
romise
;
return
deferred
.
p
romise
;
}
__exports__
.
all
=
all
;
...
...
@@ -270,6 +263,60 @@ define("rsvp/events",
__exports__
.
EventTarget
=
EventTarget
;
});
define
(
"
rsvp/hash
"
,
[
"
rsvp/defer
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
defer
=
__dependency1__
.
defer
;
function
size
(
object
)
{
var
size
=
0
;
for
(
var
prop
in
object
)
{
size
++
;
}
return
size
;
}
function
hash
(
promises
)
{
var
results
=
{},
deferred
=
defer
(),
remaining
=
size
(
promises
);
if
(
remaining
===
0
)
{
deferred
.
resolve
({});
}
var
resolver
=
function
(
prop
)
{
return
function
(
value
)
{
resolveAll
(
prop
,
value
);
};
};
var
resolveAll
=
function
(
prop
,
value
)
{
results
[
prop
]
=
value
;
if
(
--
remaining
===
0
)
{
deferred
.
resolve
(
results
);
}
};
var
rejectAll
=
function
(
error
)
{
deferred
.
reject
(
error
);
};
for
(
var
prop
in
promises
)
{
if
(
promises
[
prop
]
&&
typeof
promises
[
prop
].
then
===
'
function
'
)
{
promises
[
prop
].
then
(
resolver
(
prop
),
rejectAll
);
}
else
{
resolveAll
(
prop
,
promises
[
prop
]);
}
}
return
deferred
.
promise
;
}
__exports__
.
hash
=
hash
;
});
define
(
"
rsvp/node
"
,
[
"
rsvp/promise
"
,
"
rsvp/all
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__exports__
)
{
...
...
@@ -456,15 +503,16 @@ define("rsvp/promise",
});
define
(
"
rsvp
"
,
[
"
rsvp/events
"
,
"
rsvp/promise
"
,
"
rsvp/node
"
,
"
rsvp/all
"
,
"
rsvp/defer
"
,
"
rsvp/config
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__dependency3__
,
__dependency4__
,
__dependency5__
,
__dependency6__
,
__exports__
)
{
[
"
rsvp/events
"
,
"
rsvp/promise
"
,
"
rsvp/node
"
,
"
rsvp/all
"
,
"
rsvp/
hash
"
,
"
rsvp/
defer
"
,
"
rsvp/config
"
,
"
exports
"
],
function
(
__dependency1__
,
__dependency2__
,
__dependency3__
,
__dependency4__
,
__dependency5__
,
__dependency6__
,
__
dependency7__
,
__
exports__
)
{
"
use strict
"
;
var
EventTarget
=
__dependency1__
.
EventTarget
;
var
Promise
=
__dependency2__
.
Promise
;
var
denodeify
=
__dependency3__
.
denodeify
;
var
all
=
__dependency4__
.
all
;
var
defer
=
__dependency5__
.
defer
;
var
config
=
__dependency6__
.
config
;
var
hash
=
__dependency5__
.
hash
;
var
defer
=
__dependency6__
.
defer
;
var
config
=
__dependency7__
.
config
;
function
configure
(
name
,
value
)
{
config
[
name
]
=
value
;
...
...
@@ -473,6 +521,7 @@ define("rsvp",
__exports__
.
Promise
=
Promise
;
__exports__
.
EventTarget
=
EventTarget
;
__exports__
.
all
=
all
;
__exports__
.
hash
=
hash
;
__exports__
.
defer
=
defer
;
__exports__
.
denodeify
=
denodeify
;
__exports__
.
configure
=
configure
;
...
...
browser/rsvp.min.js
View file @
8a24804f
This diff is collapsed.
Click to expand it.
browser/rsvp/all.amd.js
View file @
8a24804f
define
(
[
"
rsvp/
promise
"
,
"
exports
"
],
[
"
rsvp/
defer
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
Promise
=
__dependency1__
.
Promise
;
var
defer
=
__dependency1__
.
defer
;
function
all
(
promises
)
{
var
i
,
results
=
[],
resolve
,
reject
;
var
allPromise
=
new
Promise
(
function
(
allResolver
,
allRejecter
)
{
resolve
=
allResolver
;
reject
=
allRejecter
;
});
var
remaining
=
promises
.
length
;
var
results
=
[],
deferred
=
defer
(),
remaining
=
promises
.
length
;
if
(
remaining
===
0
)
{
resolve
([]);
deferred
.
resolve
([]);
}
var
resolver
=
function
(
index
)
{
...
...
@@ -27,22 +20,22 @@ define(
var
resolveAll
=
function
(
index
,
value
)
{
results
[
index
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
deferred
.
resolve
(
results
);
}
};
var
rejectAll
=
function
(
error
)
{
reject
(
error
);
deferred
.
reject
(
error
);
};
for
(
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
if
(
promises
[
i
]
&&
typeof
promises
[
i
].
then
===
'
function
'
)
{
promises
[
i
].
then
(
resolver
(
i
),
rejectAll
);
}
else
{
resolveAll
(
i
,
promises
[
i
]);
}
}
return
allP
romise
;
return
deferred
.
p
romise
;
}
__exports__
.
all
=
all
;
...
...
browser/rsvp/hash.amd.js
0 → 100644
View file @
8a24804f
define
(
[
"
rsvp/defer
"
,
"
exports
"
],
function
(
__dependency1__
,
__exports__
)
{
"
use strict
"
;
var
defer
=
__dependency1__
.
defer
;
function
size
(
object
)
{
var
size
=
0
;
for
(
var
prop
in
object
)
{
size
++
;
}
return
size
;
}
function
hash
(
promises
)
{
var
results
=
{},
deferred
=
defer
(),
remaining
=
size
(
promises
);
if
(
remaining
===
0
)
{
deferred
.
resolve
({});
}
var
resolver
=
function
(
prop
)
{
return
function
(
value
)
{
resolveAll
(
prop
,
value
);
};
};
var
resolveAll
=
function
(
prop
,
value
)
{
results
[
prop
]
=
value
;
if
(
--
remaining
===
0
)
{
deferred
.
resolve
(
results
);
}
};
var
rejectAll
=
function
(
error
)
{
deferred
.
reject
(
error
);
};
for
(
var
prop
in
promises
)
{
if
(
promises
[
prop
]
&&
typeof
promises
[
prop
].
then
===
'
function
'
)
{
promises
[
prop
].
then
(
resolver
(
prop
),
rejectAll
);
}
else
{
resolveAll
(
prop
,
promises
[
prop
]);
}
}
return
deferred
.
promise
;
}
__exports__
.
hash
=
hash
;
});
lib/rsvp.js
View file @
8a24804f
...
...
@@ -2,6 +2,7 @@ import { EventTarget } from "rsvp/events";
import
{
Promise
}
from
"
rsvp/promise
"
;
import
{
denodeify
}
from
"
rsvp/node
"
;
import
{
all
}
from
"
rsvp/all
"
;
import
{
hash
}
from
"
rsvp/hash
"
;
import
{
defer
}
from
"
rsvp/defer
"
;
import
{
config
}
from
"
rsvp/config
"
;
...
...
@@ -9,4 +10,4 @@ function configure(name, value) {
config
[
name
]
=
value
;
}
export
{
Promise
,
EventTarget
,
all
,
defer
,
denodeify
,
configure
};
\ No newline at end of file
export
{
Promise
,
EventTarget
,
all
,
hash
,
defer
,
denodeify
,
configure
};
\ No newline at end of file
lib/rsvp/all.js
View file @
8a24804f
import
{
Promise
}
from
"
rsvp/promise
"
;
import
{
defer
}
from
"
rsvp/defer
"
;
function
all
(
promises
)
{
var
i
,
results
=
[],
resolve
,
reject
;
var
allPromise
=
new
Promise
(
function
(
allResolver
,
allRejecter
)
{
resolve
=
allResolver
;
reject
=
allRejecter
;
});
var
remaining
=
promises
.
length
;
var
results
=
[],
deferred
=
defer
(),
remaining
=
promises
.
length
;
if
(
remaining
===
0
)
{
resolve
([]);
deferred
.
resolve
([]);
}
var
resolver
=
function
(
index
)
{
...
...
@@ -23,22 +16,22 @@ function all(promises) {
var
resolveAll
=
function
(
index
,
value
)
{
results
[
index
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
deferred
.
resolve
(
results
);
}
};
var
rejectAll
=
function
(
error
)
{
reject
(
error
);
deferred
.
reject
(
error
);
};
for
(
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
if
(
promises
[
i
]
&&
typeof
promises
[
i
].
then
===
'
function
'
)
{
promises
[
i
].
then
(
resolver
(
i
),
rejectAll
);
}
else
{
resolveAll
(
i
,
promises
[
i
]);
}
}
return
allP
romise
;
return
deferred
.
p
romise
;
}
export
{
all
};
\ No newline at end of file
lib/rsvp/hash.js
0 → 100644
View file @
8a24804f
import
{
defer
}
from
"
rsvp/defer
"
;
function
size
(
object
)
{
var
size
=
0
;
for
(
var
prop
in
object
)
{
size
++
;
}
return
size
;
}
function
hash
(
promises
)
{
var
results
=
{},
deferred
=
defer
(),
remaining
=
size
(
promises
);
if
(
remaining
===
0
)
{
deferred
.
resolve
({});
}
var
resolver
=
function
(
prop
)
{
return
function
(
value
)
{
resolveAll
(
prop
,
value
);
};
};
var
resolveAll
=
function
(
prop
,
value
)
{
results
[
prop
]
=
value
;
if
(
--
remaining
===
0
)
{
deferred
.
resolve
(
results
);
}
};
var
rejectAll
=
function
(
error
)
{
deferred
.
reject
(
error
);
};
for
(
var
prop
in
promises
)
{
if
(
promises
[
prop
]
&&
typeof
promises
[
prop
].
then
===
'
function
'
)
{
promises
[
prop
].
then
(
resolver
(
prop
),
rejectAll
);
}
else
{
resolveAll
(
prop
,
promises
[
prop
]);
}
}
return
deferred
.
promise
;
}
export
{
hash
};
\ No newline at end of file
tests/extension-tests.js
View file @
8a24804f
...
...
@@ -322,6 +322,92 @@ describe("RSVP extensions", function() {
});
});
describe
(
"
RSVP.hash
"
,
function
()
{
it
(
'
should exist
'
,
function
()
{
assert
(
RSVP
.
hash
);
});
specify
(
'
fulfilled only after all of the promise values are fulfilled
'
,
function
(
done
)
{
var
firstResolved
,
secondResolved
,
firstResolver
,
secondResolver
;
var
first
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
firstResolver
=
resolve
;
});
first
.
then
(
function
()
{
firstResolved
=
true
;
});
var
second
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
secondResolver
=
resolve
;
});
second
.
then
(
function
()
{
secondResolved
=
true
;
});
setTimeout
(
function
()
{
firstResolver
(
true
);
},
0
);
setTimeout
(
function
()
{
secondResolver
(
true
);
},
0
);
RSVP
.
hash
({
first
:
first
,
second
:
second
}).
then
(
function
(
values
)
{
assert
(
values
.
first
);
assert
(
values
.
second
);
done
();
});
});
specify
(
'
rejected as soon as a promise is rejected
'
,
function
(
done
)
{
var
firstResolver
,
secondResolver
;
var
first
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
firstResolver
=
{
resolve
:
resolve
,
reject
:
reject
};
});
var
second
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
secondResolver
=
{
resolve
:
resolve
,
reject
:
reject
};
});
setTimeout
(
function
()
{
firstResolver
.
reject
({});
},
0
);
setTimeout
(
function
()
{
secondResolver
.
resolve
(
true
);
},
5000
);
RSVP
.
hash
({
first
:
first
,
second
:
second
}).
then
(
function
()
{
assert
(
false
);
},
function
()
{
assert
(
first
.
isRejected
);
assert
(
!
second
.
isResolved
);
done
();
});
});
specify
(
'
resolves an empty hash passed to RSVP.all()
'
,
function
(
done
)
{
RSVP
.
hash
({}).
then
(
function
(
results
)
{
assert
.
deepEqual
(
results
,
{});
done
();
});
});
specify
(
'
works with a mix of promises and thenables and non-promises
'
,
function
(
done
)
{
var
promise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
resolve
(
1
);
});
var
syncThenable
=
{
then
:
function
(
onFulfilled
)
{
onFulfilled
(
2
);
}
};
var
asyncThenable
=
{
then
:
function
(
onFulfilled
)
{
setTimeout
(
function
()
{
onFulfilled
(
3
);
},
0
);
}
};
var
nonPromise
=
4
;
RSVP
.
hash
({
promise
:
promise
,
syncThenable
:
syncThenable
,
asyncThenable
:
asyncThenable
,
nonPromise
:
nonPromise
}).
then
(
function
(
results
)
{
assert
.
deepEqual
(
results
,
{
promise
:
1
,
syncThenable
:
2
,
asyncThenable
:
3
,
nonPromise
:
4
});
done
();
});
});
});
describe
(
"
RSVP.all
"
,
function
()
{
it
(
'
should exist
'
,
function
()
{
assert
(
RSVP
.
all
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment