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
Boris Kocherov
rsvp.js
Commits
914bd203
Commit
914bd203
authored
Jan 11, 2013
by
tomhuda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix node distribution
parent
b1b90dae
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
274 additions
and
7 deletions
+274
-7
.gitignore
.gitignore
+4
-1
.npmignore
.npmignore
+1
-0
Rakefile
Rakefile
+12
-1
browser/rsvp.amd.js
browser/rsvp.amd.js
+1
-1
browser/rsvp.js
browser/rsvp.js
+1
-1
browser/rsvp.min.js
browser/rsvp.min.js
+1
-1
component.json
component.json
+1
-1
lib/rsvp.js
lib/rsvp.js
+1
-1
node/rsvp.js
node/rsvp.js
+246
-0
tests/rsvp.js
tests/rsvp.js
+6
-0
No files found.
.gitignore
View file @
914bd203
/node_modules
promise-tests/
/promise-tests/
/promises-tests/
/promises-aplus-tests/
/.bundle
.npmignore
View file @
914bd203
...
...
@@ -9,3 +9,4 @@
/tests/
/promises-aplus-tests
/promise-tests # for orphans left from earlier versions
/lib
Rakefile
View file @
914bd203
...
...
@@ -2,6 +2,7 @@ require "bundler/setup"
require
"js_module_transpiler"
directory
"browser"
directory
"node"
file
"browser/rsvp.js"
=>
[
"browser"
,
"lib/rsvp.js"
]
do
library
=
File
.
read
(
"lib/rsvp.js"
)
...
...
@@ -21,6 +22,16 @@ file "browser/rsvp.amd.js" => ["browser", "lib/rsvp.js"] do
end
end
file
"node/rsvp.js"
=>
[
"node"
,
"lib/rsvp.js"
]
do
library
=
File
.
read
(
"lib/rsvp.js"
)
open
"node/rsvp.js"
,
"w"
do
|
file
|
require
"js_module_transpiler"
converter
=
JsModuleTranspiler
::
Compiler
.
new
(
File
.
read
(
"./lib/rsvp.js"
),
"rsvp"
)
file
.
puts
converter
.
to_cjs
end
end
file
"browser/rsvp.min.js"
=>
"browser/rsvp.js"
do
output
=
`cat browser/rsvp.js | uglifyjs`
...
...
@@ -39,7 +50,7 @@ file "tests/rsvp.js" => "lib/rsvp.js" do
end
end
task
:dist
=>
[
"browser/rsvp.js"
,
"browser/rsvp.min.js"
,
"browser/rsvp.amd.js"
]
task
:dist
=>
[
"browser/rsvp.js"
,
"browser/rsvp.min.js"
,
"browser/rsvp.amd.js"
,
"node/rsvp.js"
]
task
:push
=>
:dist
do
sh
"git add browser/rsvp.js browser/rsvp.min.js browser/rsvp.amd.js"
...
...
browser/rsvp.amd.js
View file @
914bd203
...
...
@@ -245,6 +245,6 @@ define("rsvp",
EventTarget
.
mixin
(
Promise
.
prototype
);
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
};
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
,
raiseOnUncaughtExceptions
:
true
};
return
RSVP
;
});
browser/rsvp.js
View file @
914bd203
...
...
@@ -243,6 +243,6 @@
EventTarget
.
mixin
(
Promise
.
prototype
);
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
};
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
,
raiseOnUncaughtExceptions
:
true
};
exports
.
RSVP
=
RSVP
;
})(
window
);
browser/rsvp.min.js
View file @
914bd203
(
function
(
e
xports
){
"
use strict
"
;
var
browserGlobal
=
typeof
window
!==
"
undefined
"
?
window
:{};
var
MutationObserver
=
browserGlobal
.
MutationObserver
||
browserGlobal
.
WebKitMutationObserver
;
var
RSVP
,
async
;
if
(
typeof
process
!==
"
undefined
"
&&
{}.
toString
.
call
(
process
)
===
"
[object process]
"
){
async
=
function
(
callback
,
binding
){
process
.
nextTick
(
function
(){
callback
.
call
(
binding
)})}}
else
if
(
MutationObserver
){
var
queue
=
[];
var
observer
=
new
MutationObserver
(
function
(){
var
toProcess
=
queue
.
slice
();
queue
=
[];
toProcess
.
forEach
(
function
(
tuple
){
var
callback
=
tuple
[
0
],
binding
=
tuple
[
1
];
callback
.
call
(
binding
)})});
var
element
=
document
.
createElement
(
"
div
"
);
observer
.
observe
(
element
,{
attributes
:
true
});
window
.
addEventListener
(
"
unload
"
,
function
(){
observer
.
disconnect
();
observer
=
null
});
async
=
function
(
callback
,
binding
){
queue
.
push
([
callback
,
binding
]);
element
.
setAttribute
(
"
drainQueue
"
,
"
drainQueue
"
)}}
else
{
async
=
function
(
callback
,
binding
){
setTimeout
(
function
(){
callback
.
call
(
binding
)},
1
)}}
var
Event
=
function
(
type
,
options
){
this
.
type
=
type
;
for
(
var
option
in
options
){
if
(
!
options
.
hasOwnProperty
(
option
)){
continue
}
this
[
option
]
=
options
[
option
]}};
var
indexOf
=
function
(
callbacks
,
callback
){
for
(
var
i
=
0
,
l
=
callbacks
.
length
;
i
<
l
;
i
++
){
if
(
callbacks
[
i
][
0
]
===
callback
){
return
i
}}
return
-
1
};
var
callbacksFor
=
function
(
object
){
var
callbacks
=
object
.
_promiseCallbacks
;
if
(
!
callbacks
){
callbacks
=
object
.
_promiseCallbacks
=
{}}
return
callbacks
};
var
EventTarget
=
{
mixin
:
function
(
object
){
object
.
on
=
this
.
on
;
object
.
off
=
this
.
off
;
object
.
trigger
=
this
.
trigger
;
return
object
},
on
:
function
(
eventNames
,
callback
,
binding
){
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
eventName
;
eventNames
=
eventNames
.
split
(
/
\s
+/
);
binding
=
binding
||
this
;
while
(
eventName
=
eventNames
.
shift
()){
callbacks
=
allCallbacks
[
eventName
];
if
(
!
callbacks
){
callbacks
=
allCallbacks
[
eventName
]
=
[]}
if
(
indexOf
(
callbacks
,
callback
)
===-
1
){
callbacks
.
push
([
callback
,
binding
])}}},
off
:
function
(
eventNames
,
callback
){
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
eventName
,
index
;
eventNames
=
eventNames
.
split
(
/
\s
+/
);
while
(
eventName
=
eventNames
.
shift
()){
if
(
!
callback
){
allCallbacks
[
eventName
]
=
[];
continue
}
callbacks
=
allCallbacks
[
eventName
];
index
=
indexOf
(
callbacks
,
callback
);
if
(
index
!==-
1
){
callbacks
.
splice
(
index
,
1
)}}},
trigger
:
function
(
eventName
,
options
){
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
callbackTuple
,
callback
,
binding
,
event
;
if
(
callbacks
=
allCallbacks
[
eventName
]){
for
(
var
i
=
0
,
l
=
callbacks
.
length
;
i
<
l
;
i
++
){
callbackTuple
=
callbacks
[
i
];
callback
=
callbackTuple
[
0
];
binding
=
callbackTuple
[
1
];
if
(
typeof
options
!==
"
object
"
){
options
=
{
detail
:
options
}}
event
=
new
Event
(
eventName
,
options
);
callback
.
call
(
binding
,
event
)}}}};
var
Promise
=
function
(){
this
.
on
(
"
promise:resolved
"
,
function
(
event
){
this
.
trigger
(
"
success
"
,{
detail
:
event
.
detail
})},
this
);
this
.
on
(
"
promise:failed
"
,
function
(
event
){
this
.
trigger
(
"
error
"
,{
detail
:
event
.
detail
})},
this
)};
var
noop
=
function
(){};
var
invokeCallback
=
function
(
type
,
promise
,
callback
,
event
){
var
hasCallback
=
typeof
callback
===
"
function
"
,
value
,
error
,
succeeded
,
failed
;
if
(
hasCallback
){
try
{
value
=
callback
(
event
.
detail
);
succeeded
=
true
}
catch
(
e
){
failed
=
true
;
error
=
e
}}
else
{
value
=
event
.
detail
;
succeeded
=
true
}
if
(
value
&&
typeof
value
.
then
===
"
function
"
){
value
.
then
(
function
(
value
){
promise
.
resolve
(
value
)},
function
(
error
){
promise
.
reject
(
error
)})}
else
if
(
hasCallback
&&
succeeded
){
promise
.
resolve
(
value
)}
else
if
(
failed
){
promise
.
reject
(
error
)}
else
{
promise
[
type
](
value
)}};
Promise
.
prototype
=
{
then
:
function
(
done
,
fail
){
var
thenPromise
=
new
Promise
;
if
(
this
.
isResolved
){
RSVP
.
async
(
function
(){
invokeCallback
(
"
resolve
"
,
thenPromise
,
done
,{
detail
:
this
.
resolvedValue
})},
this
)}
if
(
this
.
isRejected
){
RSVP
.
async
(
function
(){
invokeCallback
(
"
reject
"
,
thenPromise
,
fail
,{
detail
:
this
.
rejectedValue
})},
this
)}
this
.
on
(
"
promise:resolved
"
,
function
(
event
){
invokeCallback
(
"
resolve
"
,
thenPromise
,
done
,
event
)});
this
.
on
(
"
promise:failed
"
,
function
(
event
){
invokeCallback
(
"
reject
"
,
thenPromise
,
fail
,
event
)});
return
thenPromise
},
resolve
:
function
(
value
){
resolve
(
this
,
value
);
this
.
resolve
=
noop
;
this
.
reject
=
noop
},
reject
:
function
(
value
){
reject
(
this
,
value
);
this
.
resolve
=
noop
;
this
.
reject
=
noop
}};
function
resolve
(
promise
,
value
){
RSVP
.
async
(
function
(){
promise
.
trigger
(
"
promise:resolved
"
,{
detail
:
value
});
promise
.
isResolved
=
true
;
promise
.
resolvedValue
=
value
})}
function
reject
(
promise
,
value
){
RSVP
.
async
(
function
(){
promise
.
trigger
(
"
promise:failed
"
,{
detail
:
value
});
promise
.
isRejected
=
true
;
promise
.
rejectedValue
=
value
})}
EventTarget
.
mixin
(
Promise
.
prototype
);
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
};
exports
.
RSVP
=
RSVP
})(
window
);
(
function
(
e
){
"
use strict
"
;
function
v
(
e
,
t
){
r
.
async
(
function
(){
e
.
trigger
(
"
promise:resolved
"
,{
detail
:
t
}),
e
.
isResolved
=!
0
,
e
.
resolvedValue
=
t
})}
function
m
(
e
,
t
){
r
.
async
(
function
(){
e
.
trigger
(
"
promise:failed
"
,{
detail
:
t
}),
e
.
isRejected
=!
0
,
e
.
rejectedValue
=
t
})}
var
t
=
typeof
window
!=
"
undefined
"
?
window
:{},
n
=
t
.
MutationObserver
||
t
.
WebKitMutationObserver
,
r
,
i
;
if
(
typeof
process
!=
"
undefined
"
&&
{}.
toString
.
call
(
process
)
===
"
[object process]
"
)
i
=
function
(
e
,
t
){
process
.
nextTick
(
function
(){
e
.
call
(
t
)})};
else
if
(
n
){
var
s
=
[],
o
=
new
n
(
function
(){
var
e
=
s
.
slice
();
s
=
[],
e
.
forEach
(
function
(
e
){
var
t
=
e
[
0
],
n
=
e
[
1
];
t
.
call
(
n
)})}),
u
=
document
.
createElement
(
"
div
"
);
o
.
observe
(
u
,{
attributes
:
!
0
}),
window
.
addEventListener
(
"
unload
"
,
function
(){
o
.
disconnect
(),
o
=
null
}),
i
=
function
(
e
,
t
){
s
.
push
([
e
,
t
]),
u
.
setAttribute
(
"
drainQueue
"
,
"
drainQueue
"
)}}
else
i
=
function
(
e
,
t
){
setTimeout
(
function
(){
e
.
call
(
t
)},
1
)};
var
a
=
function
(
e
,
t
){
this
.
type
=
e
;
for
(
var
n
in
t
){
if
(
!
t
.
hasOwnProperty
(
n
))
continue
;
this
[
n
]
=
t
[
n
]}},
f
=
function
(
e
,
t
){
for
(
var
n
=
0
,
r
=
e
.
length
;
n
<
r
;
n
++
)
if
(
e
[
n
][
0
]
===
t
)
return
n
;
return
-
1
},
l
=
function
(
e
){
var
t
=
e
.
_promiseCallbacks
;
return
t
||
(
t
=
e
.
_promiseCallbacks
=
{}),
t
},
c
=
{
mixin
:
function
(
e
){
return
e
.
on
=
this
.
on
,
e
.
off
=
this
.
off
,
e
.
trigger
=
this
.
trigger
,
e
},
on
:
function
(
e
,
t
,
n
){
var
r
=
l
(
this
),
i
,
s
;
e
=
e
.
split
(
/
\s
+/
),
n
=
n
||
this
;
while
(
s
=
e
.
shift
())
i
=
r
[
s
],
i
||
(
i
=
r
[
s
]
=
[]),
f
(
i
,
t
)
===-
1
&&
i
.
push
([
t
,
n
])},
off
:
function
(
e
,
t
){
var
n
=
l
(
this
),
r
,
i
,
s
;
e
=
e
.
split
(
/
\s
+/
);
while
(
i
=
e
.
shift
()){
if
(
!
t
){
n
[
i
]
=
[];
continue
}
r
=
n
[
i
],
s
=
f
(
r
,
t
),
s
!==-
1
&&
r
.
splice
(
s
,
1
)}},
trigger
:
function
(
e
,
t
){
var
n
=
l
(
this
),
r
,
i
,
s
,
o
,
u
;
if
(
r
=
n
[
e
])
for
(
var
f
=
0
,
c
=
r
.
length
;
f
<
c
;
f
++
)
i
=
r
[
f
],
s
=
i
[
0
],
o
=
i
[
1
],
typeof
t
!=
"
object
"
&&
(
t
=
{
detail
:
t
}),
u
=
new
a
(
e
,
t
),
s
.
call
(
o
,
u
)}},
h
=
function
(){
this
.
on
(
"
promise:resolved
"
,
function
(
e
){
this
.
trigger
(
"
success
"
,{
detail
:
e
.
detail
})},
this
),
this
.
on
(
"
promise:failed
"
,
function
(
e
){
this
.
trigger
(
"
error
"
,{
detail
:
e
.
detail
})},
this
)},
p
=
function
(){},
d
=
function
(
e
,
t
,
n
,
r
){
var
i
=
typeof
n
==
"
function
"
,
s
,
o
,
u
,
a
;
if
(
i
)
try
{
s
=
n
(
r
.
detail
),
u
=!
0
}
catch
(
f
){
a
=!
0
,
o
=
f
}
else
s
=
r
.
detail
,
u
=!
0
;
s
&&
typeof
s
.
then
==
"
function
"
?
s
.
then
(
function
(
e
){
t
.
resolve
(
e
)},
function
(
e
){
t
.
reject
(
e
)}):
i
&&
u
?
t
.
resolve
(
s
):
a
?
t
.
reject
(
o
):
t
[
e
](
s
)};
h
.
prototype
=
{
then
:
function
(
e
,
t
){
var
n
=
new
h
;
return
this
.
isResolved
&&
r
.
async
(
function
(){
d
(
"
resolve
"
,
n
,
e
,{
detail
:
this
.
resolvedValue
})},
this
),
this
.
isRejected
&&
r
.
async
(
function
(){
d
(
"
reject
"
,
n
,
t
,{
detail
:
this
.
rejectedValue
})},
this
),
this
.
on
(
"
promise:resolved
"
,
function
(
t
){
d
(
"
resolve
"
,
n
,
e
,
t
)}),
this
.
on
(
"
promise:failed
"
,
function
(
e
){
d
(
"
reject
"
,
n
,
t
,
e
)}),
n
},
resolve
:
function
(
e
){
v
(
this
,
e
),
this
.
resolve
=
p
,
this
.
reject
=
p
},
reject
:
function
(
e
){
m
(
this
,
e
),
this
.
resolve
=
p
,
this
.
reject
=
p
}},
c
.
mixin
(
h
.
prototype
),
r
=
{
async
:
i
,
Promise
:
h
,
Event
:
a
,
EventTarget
:
c
,
raiseOnUncaughtExceptions
:
!
0
},
e
.
RSVP
=
r
})(
window
);
component.json
View file @
914bd203
...
...
@@ -7,7 +7,7 @@
],
"version"
:
"1.0.0"
,
"scripts"
:
[
"
lib
/rsvp.js"
"
node
/rsvp.js"
],
"repo"
:
"tildeio/rsvp.js"
}
lib/rsvp.js
View file @
914bd203
...
...
@@ -267,5 +267,5 @@ function all(promises) {
EventTarget
.
mixin
(
Promise
.
prototype
);
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
,
all
:
all
};
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
,
all
:
all
,
raiseOnUncaughtExceptions
:
true
};
export
=
RSVP
;
node/rsvp.js
0 → 100644
View file @
914bd203
"
use strict
"
;
var
browserGlobal
=
(
typeof
window
!==
'
undefined
'
)
?
window
:
{};
var
MutationObserver
=
browserGlobal
.
MutationObserver
||
browserGlobal
.
WebKitMutationObserver
;
var
RSVP
,
async
;
if
(
typeof
process
!==
'
undefined
'
&&
{}.
toString
.
call
(
process
)
===
'
[object process]
'
)
{
async
=
function
(
callback
,
binding
)
{
process
.
nextTick
(
function
()
{
callback
.
call
(
binding
);
});
};
}
else
if
(
MutationObserver
)
{
var
queue
=
[];
var
observer
=
new
MutationObserver
(
function
()
{
var
toProcess
=
queue
.
slice
();
queue
=
[];
toProcess
.
forEach
(
function
(
tuple
)
{
var
callback
=
tuple
[
0
],
binding
=
tuple
[
1
];
callback
.
call
(
binding
);
});
});
var
element
=
document
.
createElement
(
'
div
'
);
observer
.
observe
(
element
,
{
attributes
:
true
});
// Chrome Memory Leak: https://bugs.webkit.org/show_bug.cgi?id=93661
window
.
addEventListener
(
'
unload
'
,
function
(){
observer
.
disconnect
();
observer
=
null
;
});
async
=
function
(
callback
,
binding
)
{
queue
.
push
([
callback
,
binding
]);
element
.
setAttribute
(
'
drainQueue
'
,
'
drainQueue
'
);
};
}
else
{
async
=
function
(
callback
,
binding
)
{
setTimeout
(
function
()
{
callback
.
call
(
binding
);
},
1
);
};
}
var
Event
=
function
(
type
,
options
)
{
this
.
type
=
type
;
for
(
var
option
in
options
)
{
if
(
!
options
.
hasOwnProperty
(
option
))
{
continue
;
}
this
[
option
]
=
options
[
option
];
}
};
var
indexOf
=
function
(
callbacks
,
callback
)
{
for
(
var
i
=
0
,
l
=
callbacks
.
length
;
i
<
l
;
i
++
)
{
if
(
callbacks
[
i
][
0
]
===
callback
)
{
return
i
;
}
}
return
-
1
;
};
var
callbacksFor
=
function
(
object
)
{
var
callbacks
=
object
.
_promiseCallbacks
;
if
(
!
callbacks
)
{
callbacks
=
object
.
_promiseCallbacks
=
{};
}
return
callbacks
;
};
var
EventTarget
=
{
mixin
:
function
(
object
)
{
object
.
on
=
this
.
on
;
object
.
off
=
this
.
off
;
object
.
trigger
=
this
.
trigger
;
return
object
;
},
on
:
function
(
eventNames
,
callback
,
binding
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
eventName
;
eventNames
=
eventNames
.
split
(
/
\s
+/
);
binding
=
binding
||
this
;
while
(
eventName
=
eventNames
.
shift
())
{
callbacks
=
allCallbacks
[
eventName
];
if
(
!
callbacks
)
{
callbacks
=
allCallbacks
[
eventName
]
=
[];
}
if
(
indexOf
(
callbacks
,
callback
)
===
-
1
)
{
callbacks
.
push
([
callback
,
binding
]);
}
}
},
off
:
function
(
eventNames
,
callback
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
eventName
,
index
;
eventNames
=
eventNames
.
split
(
/
\s
+/
);
while
(
eventName
=
eventNames
.
shift
())
{
if
(
!
callback
)
{
allCallbacks
[
eventName
]
=
[];
continue
;
}
callbacks
=
allCallbacks
[
eventName
];
index
=
indexOf
(
callbacks
,
callback
);
if
(
index
!==
-
1
)
{
callbacks
.
splice
(
index
,
1
);
}
}
},
trigger
:
function
(
eventName
,
options
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
callbackTuple
,
callback
,
binding
,
event
;
if
(
callbacks
=
allCallbacks
[
eventName
])
{
for
(
var
i
=
0
,
l
=
callbacks
.
length
;
i
<
l
;
i
++
)
{
callbackTuple
=
callbacks
[
i
];
callback
=
callbackTuple
[
0
];
binding
=
callbackTuple
[
1
];
if
(
typeof
options
!==
'
object
'
)
{
options
=
{
detail
:
options
};
}
event
=
new
Event
(
eventName
,
options
);
callback
.
call
(
binding
,
event
);
}
}
}
};
var
Promise
=
function
()
{
this
.
on
(
'
promise:resolved
'
,
function
(
event
)
{
this
.
trigger
(
'
success
'
,
{
detail
:
event
.
detail
});
},
this
);
this
.
on
(
'
promise:failed
'
,
function
(
event
)
{
this
.
trigger
(
'
error
'
,
{
detail
:
event
.
detail
});
},
this
);
};
var
noop
=
function
()
{};
var
invokeCallback
=
function
(
type
,
promise
,
callback
,
event
)
{
var
hasCallback
=
typeof
callback
===
'
function
'
,
value
,
error
,
succeeded
,
failed
;
if
(
hasCallback
)
{
try
{
value
=
callback
(
event
.
detail
);
succeeded
=
true
;
}
catch
(
e
)
{
failed
=
true
;
error
=
e
;
}
}
else
{
value
=
event
.
detail
;
succeeded
=
true
;
}
if
(
value
&&
typeof
value
.
then
===
'
function
'
)
{
value
.
then
(
function
(
value
)
{
promise
.
resolve
(
value
);
},
function
(
error
)
{
promise
.
reject
(
error
);
});
}
else
if
(
hasCallback
&&
succeeded
)
{
promise
.
resolve
(
value
);
}
else
if
(
failed
)
{
promise
.
reject
(
error
);
}
else
{
promise
[
type
](
value
);
}
};
Promise
.
prototype
=
{
then
:
function
(
done
,
fail
)
{
var
thenPromise
=
new
Promise
();
if
(
this
.
isResolved
)
{
RSVP
.
async
(
function
()
{
invokeCallback
(
'
resolve
'
,
thenPromise
,
done
,
{
detail
:
this
.
resolvedValue
});
},
this
);
}
if
(
this
.
isRejected
)
{
RSVP
.
async
(
function
()
{
invokeCallback
(
'
reject
'
,
thenPromise
,
fail
,
{
detail
:
this
.
rejectedValue
});
},
this
);
}
this
.
on
(
'
promise:resolved
'
,
function
(
event
)
{
invokeCallback
(
'
resolve
'
,
thenPromise
,
done
,
event
);
});
this
.
on
(
'
promise:failed
'
,
function
(
event
)
{
invokeCallback
(
'
reject
'
,
thenPromise
,
fail
,
event
);
});
return
thenPromise
;
},
resolve
:
function
(
value
)
{
resolve
(
this
,
value
);
this
.
resolve
=
noop
;
this
.
reject
=
noop
;
},
reject
:
function
(
value
)
{
reject
(
this
,
value
);
this
.
resolve
=
noop
;
this
.
reject
=
noop
;
}
};
function
resolve
(
promise
,
value
)
{
RSVP
.
async
(
function
()
{
promise
.
trigger
(
'
promise:resolved
'
,
{
detail
:
value
});
promise
.
isResolved
=
true
;
promise
.
resolvedValue
=
value
;
});
}
function
reject
(
promise
,
value
)
{
RSVP
.
async
(
function
()
{
promise
.
trigger
(
'
promise:failed
'
,
{
detail
:
value
});
promise
.
isRejected
=
true
;
promise
.
rejectedValue
=
value
;
});
}
EventTarget
.
mixin
(
Promise
.
prototype
);
RSVP
=
{
async
:
async
,
Promise
:
Promise
,
Event
:
Event
,
EventTarget
:
EventTarget
,
raiseOnUncaughtExceptions
:
true
};
module
.
exports
=
RSVP
;
tests/rsvp.js
View file @
914bd203
...
...
@@ -27,6 +27,12 @@ if (typeof process !== 'undefined' &&
var
element
=
document
.
createElement
(
'
div
'
);
observer
.
observe
(
element
,
{
attributes
:
true
});
// Chrome Memory Leak: https://bugs.webkit.org/show_bug.cgi?id=93661
window
.
addEventListener
(
'
unload
'
,
function
(){
observer
.
disconnect
();
observer
=
null
;
});
async
=
function
(
callback
,
binding
)
{
queue
.
push
([
callback
,
binding
]);
element
.
setAttribute
(
'
drainQueue
'
,
'
drainQueue
'
);
...
...
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