Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd.js
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
regiostart
psd.js
Commits
fe58a3f6
Commit
fe58a3f6
authored
May 10, 2014
by
Ryan LeFevre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish Descriptor implementation
parent
91584282
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2044 additions
and
22 deletions
+2044
-22
Cakefile
Cakefile
+2
-1
psd.js
dist/psd.js
+1984
-18
descriptor.coffee
lib/psd/descriptor.coffee
+58
-3
No files found.
Cakefile
View file @
fe58a3f6
...
@@ -13,4 +13,5 @@ task 'compile', 'Compile with browserify for the web', ->
...
@@ -13,4 +13,5 @@ task 'compile', 'Compile with browserify for the web', ->
.
bundle
(
err
,
src
)
->
.
bundle
(
err
,
src
)
->
return
console
.
log
(
err
)
if
err
?
return
console
.
log
(
err
)
if
err
?
fs
.
writeFile
'./dist/psd.js'
,
src
,
->
fs
.
writeFile
'./dist/psd.js'
,
src
,
->
console
.
log
"Compiled to ./dist/psd.js"
fs
.
stat
'./dist/psd.js'
,
(
err
,
stats
)
->
\ No newline at end of file
console
.
log
"Compiled to ./dist/psd.js -
#{
Math
.
round
(
stats
.
size
/
1024
)
}
KB"
\ No newline at end of file
dist/psd.js
View file @
fe58a3f6
...
@@ -80,7 +80,7 @@ module.exports = PSD = (function(_super) {
...
@@ -80,7 +80,7 @@ module.exports = PSD = (function(_super) {
})(
Module
);
})(
Module
);
},{
"./psd/file.coffee"
:
3
,
"./psd/header.coffee"
:
4
,
"./psd/image.coffee"
:
5
,
"./psd/init.coffee"
:
"/ioUh4"
,
"./psd/layer_mask.coffee"
:
24
,
"./psd/lazy_execute.coffee"
:
25
,
"./psd/nodes/root.coffee"
:
31
,
"./psd/resources.coffee"
:
33
,
"coffeescript-module"
:
3
5
}],
2
:[
function
(
require
,
module
,
exports
){
},{
"./psd/file.coffee"
:
3
,
"./psd/header.coffee"
:
4
,
"./psd/image.coffee"
:
5
,
"./psd/init.coffee"
:
"/ioUh4"
,
"./psd/layer_mask.coffee"
:
24
,
"./psd/lazy_execute.coffee"
:
25
,
"./psd/nodes/root.coffee"
:
31
,
"./psd/resources.coffee"
:
33
,
"coffeescript-module"
:
3
6
}],
2
:[
function
(
require
,
module
,
exports
){
var
BlendMode
,
Module
,
var
BlendMode
,
Module
,
__hasProp
=
{}.
hasOwnProperty
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
...
@@ -155,7 +155,7 @@ module.exports = BlendMode = (function(_super) {
...
@@ -155,7 +155,7 @@ module.exports = BlendMode = (function(_super) {
})(
Module
);
})(
Module
);
},{
"coffeescript-module"
:
3
5
}],
3
:[
function
(
require
,
module
,
exports
){
},{
"coffeescript-module"
:
3
6
}],
3
:[
function
(
require
,
module
,
exports
){
var
File
,
Util
,
jspack
,
var
File
,
Util
,
jspack
,
__hasProp
=
{}.
hasOwnProperty
;
__hasProp
=
{}.
hasOwnProperty
;
...
@@ -269,7 +269,7 @@ module.exports = File = (function() {
...
@@ -269,7 +269,7 @@ module.exports = File = (function() {
})();
})();
},{
"./util.coffee"
:
34
,
"jspack"
:
3
7
}],
4
:[
function
(
require
,
module
,
exports
){
},{
"./util.coffee"
:
34
,
"jspack"
:
3
8
}],
4
:[
function
(
require
,
module
,
exports
){
var
Header
;
var
Header
;
module
.
exports
=
Header
=
(
function
()
{
module
.
exports
=
Header
=
(
function
()
{
...
@@ -457,7 +457,7 @@ module.exports = Image = (function(_super) {
...
@@ -457,7 +457,7 @@ module.exports = Image = (function(_super) {
})(
Module
);
})(
Module
);
},{
"./image_export.coffee"
:
6
,
"./image_format.coffee"
:
7
,
"./image_mode.coffee"
:
10
,
"coffeescript-module"
:
3
5
}],
6
:[
function
(
require
,
module
,
exports
){
},{
"./image_export.coffee"
:
6
,
"./image_format.coffee"
:
7
,
"./image_mode.coffee"
:
10
,
"coffeescript-module"
:
3
6
}],
6
:[
function
(
require
,
module
,
exports
){
module
.
exports
=
{
module
.
exports
=
{
PNG
:
require
(
'./image_exports/png.coffee'
)
PNG
:
require
(
'./image_exports/png.coffee'
)
};
};
...
@@ -666,7 +666,7 @@ module.exports = Layer = (function(_super) {
...
@@ -666,7 +666,7 @@ module.exports = Layer = (function(_super) {
})(
Module
);
})(
Module
);
},{
"./layer/blend_modes.coffee"
:
13
,
"./layer/blending_ranges.coffee"
:
14
,
"./layer/helpers.coffee"
:
15
,
"./layer/info.coffee"
:
16
,
"./layer/mask.coffee"
:
17
,
"./layer/name.coffee"
:
18
,
"./layer/position_channels.coffee"
:
19
,
"coffeescript-module"
:
3
5
}],
13
:[
function
(
require
,
module
,
exports
){
},{
"./layer/blend_modes.coffee"
:
13
,
"./layer/blending_ranges.coffee"
:
14
,
"./layer/helpers.coffee"
:
15
,
"./layer/info.coffee"
:
16
,
"./layer/mask.coffee"
:
17
,
"./layer/name.coffee"
:
18
,
"./layer/position_channels.coffee"
:
19
,
"coffeescript-module"
:
3
6
}],
13
:[
function
(
require
,
module
,
exports
){
var
BlendMode
;
var
BlendMode
;
BlendMode
=
require
(
'../blend_mode.coffee'
);
BlendMode
=
require
(
'../blend_mode.coffee'
);
...
@@ -1392,7 +1392,7 @@ module.exports = Node = (function(_super) {
...
@@ -1392,7 +1392,7 @@ module.exports = Node = (function(_super) {
})(
Module
);
})(
Module
);
},{
"./nodes/ancestry.coffee"
:
28
,
"./nodes/search.coffee"
:
32
,
"coffeescript-module"
:
3
5
,
"lodash"
:
38
}],
28
:[
function
(
require
,
module
,
exports
){
},{
"./nodes/ancestry.coffee"
:
28
,
"./nodes/search.coffee"
:
32
,
"coffeescript-module"
:
3
6
,
"lodash"
:
39
}],
28
:[
function
(
require
,
module
,
exports
){
var
_
;
var
_
;
_
=
require
(
'lodash'
);
_
=
require
(
'lodash'
);
...
@@ -1478,7 +1478,7 @@ module.exports = {
...
@@ -1478,7 +1478,7 @@ module.exports = {
};
};
},{
"lodash"
:
3
8
}],
29
:[
function
(
require
,
module
,
exports
){
},{
"lodash"
:
3
9
}],
29
:[
function
(
require
,
module
,
exports
){
var
Group
,
Node
,
_
,
var
Group
,
Node
,
_
,
__hasProp
=
{}.
hasOwnProperty
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
...
@@ -1530,7 +1530,7 @@ module.exports = Group = (function(_super) {
...
@@ -1530,7 +1530,7 @@ module.exports = Group = (function(_super) {
})(
Node
);
})(
Node
);
},{
"../node.coffee"
:
27
,
"lodash"
:
3
8
}],
30
:[
function
(
require
,
module
,
exports
){
},{
"../node.coffee"
:
27
,
"lodash"
:
3
9
}],
30
:[
function
(
require
,
module
,
exports
){
var
Layer
,
Node
,
_
,
var
Layer
,
Node
,
_
,
__hasProp
=
{}.
hasOwnProperty
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
...
@@ -1565,7 +1565,7 @@ module.exports = Layer = (function(_super) {
...
@@ -1565,7 +1565,7 @@ module.exports = Layer = (function(_super) {
})(
Node
);
})(
Node
);
},{
"../node.coffee"
:
27
,
"lodash"
:
3
8
}],
31
:[
function
(
require
,
module
,
exports
){
},{
"../node.coffee"
:
27
,
"lodash"
:
3
9
}],
31
:[
function
(
require
,
module
,
exports
){
var
Group
,
Layer
,
Node
,
Root
,
_
,
var
Group
,
Layer
,
Node
,
Root
,
_
,
__hasProp
=
{}.
hasOwnProperty
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
...
@@ -1663,7 +1663,7 @@ module.exports = Root = (function(_super) {
...
@@ -1663,7 +1663,7 @@ module.exports = Root = (function(_super) {
})(
Node
);
})(
Node
);
},{
"../node.coffee"
:
27
,
"./group.coffee"
:
29
,
"./layer.coffee"
:
30
,
"lodash"
:
3
8
}],
32
:[
function
(
require
,
module
,
exports
){
},{
"../node.coffee"
:
27
,
"./group.coffee"
:
29
,
"./layer.coffee"
:
30
,
"lodash"
:
3
9
}],
32
:[
function
(
require
,
module
,
exports
){
var
_
;
var
_
;
_
=
require
(
'lodash'
);
_
=
require
(
'lodash'
);
...
@@ -1699,7 +1699,7 @@ module.exports = {
...
@@ -1699,7 +1699,7 @@ module.exports = {
};
};
},{
"lodash"
:
3
8
}],
33
:[
function
(
require
,
module
,
exports
){
},{
"lodash"
:
3
9
}],
33
:[
function
(
require
,
module
,
exports
){
var
Resources
;
var
Resources
;
module
.
exports
=
Resources
=
(
function
()
{
module
.
exports
=
Resources
=
(
function
()
{
...
@@ -1757,8 +1757,70 @@ module.exports = Util = (function() {
...
@@ -1757,8 +1757,70 @@ module.exports = Util = (function() {
},{}],
35
:[
function
(
require
,
module
,
exports
){
},{}],
35
:[
function
(
require
,
module
,
exports
){
// shim for using process in browser
var
process
=
module
.
exports
=
{};
process
.
nextTick
=
(
function
()
{
var
canSetImmediate
=
typeof
window
!==
'undefined'
&&
window
.
setImmediate
;
var
canPost
=
typeof
window
!==
'undefined'
&&
window
.
postMessage
&&
window
.
addEventListener
;
if
(
canSetImmediate
)
{
return
function
(
f
)
{
return
window
.
setImmediate
(
f
)
};
}
if
(
canPost
)
{
var
queue
=
[];
window
.
addEventListener
(
'message'
,
function
(
ev
)
{
var
source
=
ev
.
source
;
if
((
source
===
window
||
source
===
null
)
&&
ev
.
data
===
'process-tick'
)
{
ev
.
stopPropagation
();
if
(
queue
.
length
>
0
)
{
var
fn
=
queue
.
shift
();
fn
();
}
}
},
true
);
return
function
nextTick
(
fn
)
{
queue
.
push
(
fn
);
window
.
postMessage
(
'process-tick'
,
'*'
);
};
}
return
function
nextTick
(
fn
)
{
setTimeout
(
fn
,
0
);
};
})();
process
.
title
=
'browser'
;
process
.
browser
=
true
;
process
.
env
=
{};
process
.
argv
=
[];
function
noop
()
{}
process
.
on
=
noop
;
process
.
once
=
noop
;
process
.
off
=
noop
;
process
.
emit
=
noop
;
process
.
binding
=
function
(
name
)
{
throw
new
Error
(
'process.binding is not supported'
);
}
// TODO(shtylman)
process
.
cwd
=
function
()
{
return
'/'
};
process
.
chdir
=
function
(
dir
)
{
throw
new
Error
(
'process.chdir is not supported'
);
};
},{}],
36
:[
function
(
require
,
module
,
exports
){
module
.
exports
=
require
(
'./module'
);
module
.
exports
=
require
(
'./module'
);
},{
"./module"
:
3
6
}],
36
:[
function
(
require
,
module
,
exports
){
},{
"./module"
:
3
7
}],
37
:[
function
(
require
,
module
,
exports
){
// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.7.1
var
Module
,
moduleKeywords
,
var
Module
,
moduleKeywords
,
__indexOf
=
[].
indexOf
||
function
(
item
)
{
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
if
(
i
in
this
&&
this
[
i
]
===
item
)
return
i
;
}
return
-
1
;
},
__indexOf
=
[].
indexOf
||
function
(
item
)
{
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
if
(
i
in
this
&&
this
[
i
]
===
item
)
return
i
;
}
return
-
1
;
},
...
@@ -1838,7 +1900,7 @@ exports.Module = Module = (function() {
...
@@ -1838,7 +1900,7 @@ exports.Module = Module = (function() {
})();
})();
},{}],
3
7
:[
function
(
require
,
module
,
exports
){
},{}],
3
8
:[
function
(
require
,
module
,
exports
){
/*!
/*!
* Copyright © 2008 Fair Oaks Labs, Inc.
* Copyright © 2008 Fair Oaks Labs, Inc.
* All rights reserved.
* All rights reserved.
...
@@ -2094,7 +2156,7 @@ function JSPack()
...
@@ -2094,7 +2156,7 @@ function JSPack()
exports
.
jspack
=
new
JSPack
();
exports
.
jspack
=
new
JSPack
();
},{}],
3
8
:[
function
(
require
,
module
,
exports
){
},{}],
3
9
:[
function
(
require
,
module
,
exports
){
(
function
(
global
){
(
function
(
global
){
/**
/**
* @license
* @license
...
@@ -8883,19 +8945,1921 @@ exports.jspack = new JSPack();
...
@@ -8883,19 +8945,1921 @@ exports.jspack = new JSPack();
}.
call
(
this
));
}.
call
(
this
));
}).
call
(
this
,
typeof
self
!==
"undefined"
?
self
:
typeof
window
!==
"undefined"
?
window
:
{})
}).
call
(
this
,
typeof
self
!==
"undefined"
?
self
:
typeof
window
!==
"undefined"
?
window
:
{})
},{}],
40
:[
function
(
require
,
module
,
exports
){
"use strict"
;
var
Promise
=
require
(
"./rsvp/promise"
)[
"default"
];
var
EventTarget
=
require
(
"./rsvp/events"
)[
"default"
];
var
denodeify
=
require
(
"./rsvp/node"
)[
"default"
];
var
all
=
require
(
"./rsvp/all"
)[
"default"
];
var
allSettled
=
require
(
"./rsvp/all-settled"
)[
"default"
];
var
race
=
require
(
"./rsvp/race"
)[
"default"
];
var
hash
=
require
(
"./rsvp/hash"
)[
"default"
];
var
hashSettled
=
require
(
"./rsvp/hash-settled"
)[
"default"
];
var
rethrow
=
require
(
"./rsvp/rethrow"
)[
"default"
];
var
defer
=
require
(
"./rsvp/defer"
)[
"default"
];
var
config
=
require
(
"./rsvp/config"
).
config
;
var
configure
=
require
(
"./rsvp/config"
).
configure
;
var
map
=
require
(
"./rsvp/map"
)[
"default"
];
var
resolve
=
require
(
"./rsvp/resolve"
)[
"default"
];
var
reject
=
require
(
"./rsvp/reject"
)[
"default"
];
var
filter
=
require
(
"./rsvp/filter"
)[
"default"
];
var
asap
=
require
(
"./rsvp/asap"
)[
"default"
];
config
.
async
=
asap
;
// default async is asap;
function
async
(
callback
,
arg
)
{
config
.
async
(
callback
,
arg
);
}
function
on
()
{
config
.
on
.
apply
(
config
,
arguments
);
}
function
off
()
{
config
.
off
.
apply
(
config
,
arguments
);
}
// Set up instrumentation through `window.__PROMISE_INTRUMENTATION__`
if
(
typeof
window
!==
'undefined'
&&
typeof
window
.
__PROMISE_INSTRUMENTATION__
===
'object'
)
{
var
callbacks
=
window
.
__PROMISE_INSTRUMENTATION__
;
configure
(
'instrument'
,
true
);
for
(
var
eventName
in
callbacks
)
{
if
(
callbacks
.
hasOwnProperty
(
eventName
))
{
on
(
eventName
,
callbacks
[
eventName
]);
}
}
}
exports
.
Promise
=
Promise
;
exports
.
EventTarget
=
EventTarget
;
exports
.
all
=
all
;
exports
.
allSettled
=
allSettled
;
exports
.
race
=
race
;
exports
.
hash
=
hash
;
exports
.
hashSettled
=
hashSettled
;
exports
.
rethrow
=
rethrow
;
exports
.
defer
=
defer
;
exports
.
denodeify
=
denodeify
;
exports
.
configure
=
configure
;
exports
.
on
=
on
;
exports
.
off
=
off
;
exports
.
resolve
=
resolve
;
exports
.
reject
=
reject
;
exports
.
async
=
async
;
exports
.
map
=
map
;
exports
.
filter
=
filter
;
},{
"./rsvp/all"
:
42
,
"./rsvp/all-settled"
:
41
,
"./rsvp/asap"
:
43
,
"./rsvp/config"
:
44
,
"./rsvp/defer"
:
45
,
"./rsvp/events"
:
46
,
"./rsvp/filter"
:
47
,
"./rsvp/hash"
:
49
,
"./rsvp/hash-settled"
:
48
,
"./rsvp/map"
:
51
,
"./rsvp/node"
:
52
,
"./rsvp/promise"
:
53
,
"./rsvp/race"
:
59
,
"./rsvp/reject"
:
60
,
"./rsvp/resolve"
:
61
,
"./rsvp/rethrow"
:
62
}],
41
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
var
isArray
=
require
(
'./utils'
).
isArray
;
var
isNonThenable
=
require
(
'./utils'
).
isNonThenable
;
/**
`RSVP.allSettled` is similar to `RSVP.all`, but instead of implementing
a fail-fast method, it waits until all the promises have returned and
shows you all the results. This is useful if you want to handle multiple
promises' failure states together as a set.
Returns a promise that is fulfilled when all the given promises have been
settled. The return promise is fulfilled with an array of the states of
the promises passed into the `promises` array argument.
Each state object will either indicate fulfillment or rejection, and
provide the corresponding value or reason. The states will take one of
the following formats:
```javascript
{ state: 'fulfilled', value: value }
or
{ state: 'rejected', reason: reason }
```
Example:
```javascript
var promise1 = RSVP.Promise.resolve(1);
var promise2 = RSVP.Promise.reject(new Error('2'));
var promise3 = RSVP.Promise.reject(new Error('3'));
var promises = [ promise1, promise2, promise3 ];
RSVP.allSettled(promises).then(function(array){
// array == [
// { state: 'fulfilled', value: 1 },
// { state: 'rejected', reason: Error },
// { state: 'rejected', reason: Error }
// ]
// Note that for the second item, reason.message will be "2", and for the
// third item, reason.message will be "3".
}, function(error) {
// Not run. (This block would only be called if allSettled had failed,
// for instance if passed an incorrect argument type.)
});
```
@method allSettled
@static
@for RSVP
@param {Array} promises
@param {String} label - optional string that describes the promise.
Useful for tooling.
@return {Promise} promise that is fulfilled with an array of the settled
states of the constituent promises.
*/
exports
[
'default'
]
=
function
allSettled
(
entries
,
label
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
!
isArray
(
entries
))
{
throw
new
TypeError
(
'You must pass an array to allSettled.'
);
}
var
remaining
=
entries
.
length
;
var
entry
;
if
(
remaining
===
0
)
{
resolve
([]);
return
;
}
var
results
=
new
Array
(
remaining
);
function
fulfilledResolver
(
index$2
)
{
return
function
(
value
)
{
resolveAll
(
index$2
,
fulfilled
(
value
));
};
}
function
rejectedResolver
(
index$2
)
{
return
function
(
reason
)
{
resolveAll
(
index$2
,
rejected
(
reason
));
};
}
function
resolveAll
(
index$2
,
value
)
{
results
[
index$2
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
}
}
for
(
var
index
=
0
;
index
<
entries
.
length
;
index
++
)
{
entry
=
entries
[
index
];
if
(
isNonThenable
(
entry
))
{
resolveAll
(
index
,
fulfilled
(
entry
));
}
else
{
Promise
.
resolve
(
entry
).
then
(
fulfilledResolver
(
index
),
rejectedResolver
(
index
));
}
}
},
label
);
};
function
fulfilled
(
value
)
{
return
{
state
:
'fulfilled'
,
value
:
value
};
}
function
rejected
(
reason
)
{
return
{
state
:
'rejected'
,
reason
:
reason
};
}
},{
"./promise"
:
53
,
"./utils"
:
63
}],
42
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
/**
This is a convenient alias for `RSVP.Promise.all`.
@method all
@static
@for RSVP
@param {Array} array Array of promises.
@param {String} label An optional label. This is useful
for tooling.
*/
exports
[
'default'
]
=
function
all
(
array
,
label
)
{
return
Promise
.
all
(
array
,
label
);
};
},{
"./promise"
:
53
}],
43
:[
function
(
require
,
module
,
exports
){
(
function
(
process
){
'use strict'
;
exports
[
'default'
]
=
function
asap
(
callback
,
arg
)
{
var
length
=
queue
.
push
([
callback
,
arg
]);
if
(
length
===
1
)
{
// If length is 1, that means that we need to schedule an async flush.
// If additional callbacks are queued before the queue is flushed, they
// will be processed by this flush that we are scheduling.
scheduleFlush
();
}
};
var
browserGlobal
=
typeof
window
!==
'undefined'
?
window
:
{};
var
BrowserMutationObserver
=
browserGlobal
.
MutationObserver
||
browserGlobal
.
WebKitMutationObserver
;
// node
function
useNextTick
()
{
return
function
()
{
process
.
nextTick
(
flush
);
};
}
function
useMutationObserver
()
{
var
iterations
=
0
;
var
observer
=
new
BrowserMutationObserver
(
flush
);
var
node
=
document
.
createTextNode
(
''
);
observer
.
observe
(
node
,
{
characterData
:
true
});
return
function
()
{
node
.
data
=
iterations
=
++
iterations
%
2
;
};
}
function
useSetTimeout
()
{
return
function
()
{
setTimeout
(
flush
,
1
);
};
}
var
queue
=
[];
function
flush
()
{
for
(
var
i
=
0
;
i
<
queue
.
length
;
i
++
)
{
var
tuple
=
queue
[
i
];
var
callback
=
tuple
[
0
],
arg
=
tuple
[
1
];
callback
(
arg
);
}
queue
.
length
=
0
;
}
var
scheduleFlush
;
// Decide what async method to use to triggering processing of queued callbacks:
if
(
typeof
process
!==
'undefined'
&&
{}.
toString
.
call
(
process
)
===
'[object process]'
)
{
scheduleFlush
=
useNextTick
();
}
else
if
(
BrowserMutationObserver
)
{
scheduleFlush
=
useMutationObserver
();
}
else
{
scheduleFlush
=
useSetTimeout
();
}
}).
call
(
this
,
require
(
"/Users/ryanlefevre/Repositories/psd.js/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"
))
},{
"/Users/ryanlefevre/Repositories/psd.js/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"
:
35
}],
44
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
EventTarget
=
require
(
'./events'
)[
'default'
];
var
config
=
{
instrument
:
false
};
EventTarget
.
mixin
(
config
);
function
configure
(
name
,
value
)
{
if
(
name
===
'onerror'
)
{
// handle for legacy users that expect the actual
// error to be passed to their function added via
// `RSVP.configure('onerror', someFunctionHere);`
config
.
on
(
'error'
,
value
);
return
;
}
if
(
arguments
.
length
===
2
)
{
config
[
name
]
=
value
;
}
else
{
return
config
[
name
];
}
}
exports
.
config
=
config
;
exports
.
configure
=
configure
;
},{
"./events"
:
46
}],
45
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
/**
`RSVP.defer` returns an object similar to jQuery's `$.Deferred`.
`RSVP.defer` should be used when porting over code reliant on `$.Deferred`'s
interface. New code should use the `RSVP.Promise` constructor instead.
The object returned from `RSVP.defer` is a plain object with three properties:
* promise - an `RSVP.Promise`.
* reject - a function that causes the `promise` property on this object to
become rejected
* resolve - a function that causes the `promise` property on this object to
become fulfilled.
Example:
```javascript
var deferred = RSVP.defer();
deferred.resolve("Success!");
defered.promise.then(function(value){
// value here is "Success!"
});
```
@method defer
@static
@for RSVP
@param {String} label optional string for labeling the promise.
Useful for tooling.
@return {Object}
*/
exports
[
'default'
]
=
function
defer
(
label
)
{
var
deferred
=
{};
deferred
.
promise
=
new
Promise
(
function
(
resolve
,
reject
)
{
deferred
.
resolve
=
resolve
;
deferred
.
reject
=
reject
;
},
label
);
return
deferred
;
};
},{
"./promise"
:
53
}],
46
:[
function
(
require
,
module
,
exports
){
'use strict'
;
function
indexOf
(
callbacks
,
callback
)
{
for
(
var
i
=
0
,
l
=
callbacks
.
length
;
i
<
l
;
i
++
)
{
if
(
callbacks
[
i
]
===
callback
)
{
return
i
;
}
}
return
-
1
;
}
function
callbacksFor
(
object
)
{
var
callbacks
=
object
.
_promiseCallbacks
;
if
(
!
callbacks
)
{
callbacks
=
object
.
_promiseCallbacks
=
{};
}
return
callbacks
;
}
/**
@class RSVP.EventTarget
*/
exports
[
'default'
]
=
{
mixin
:
function
(
object
)
{
object
.
on
=
this
.
on
;
object
.
off
=
this
.
off
;
object
.
trigger
=
this
.
trigger
;
object
.
_promiseCallbacks
=
undefined
;
return
object
;
},
on
:
function
(
eventName
,
callback
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
;
callbacks
=
allCallbacks
[
eventName
];
if
(
!
callbacks
)
{
callbacks
=
allCallbacks
[
eventName
]
=
[];
}
if
(
indexOf
(
callbacks
,
callback
)
===
-
1
)
{
callbacks
.
push
(
callback
);
}
},
off
:
function
(
eventName
,
callback
)
{
var
allCallbacks
=
callbacksFor
(
this
),
callbacks
,
index
;
if
(
!
callback
)
{
allCallbacks
[
eventName
]
=
[];
return
;
}
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
;
if
(
callbacks
=
allCallbacks
[
eventName
])
{
// Don't cache the callbacks.length since it may grow
for
(
var
i
=
0
;
i
<
callbacks
.
length
;
i
++
)
{
callback
=
callbacks
[
i
];
callback
(
options
);
}
}
}
};
},{}],
47
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
var
isFunction
=
require
(
'./utils'
).
isFunction
;
/**
`RSVP.filter` is similar to JavaScript's native `filter` method, except that it
waits for all promises to become fulfilled before running the `filterFn` on
each item in given to `promises`. `RSVP.filter` returns a promise that will
become fulfilled with the result of running `filterFn` on the values the
promises become fulfilled with.
For example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var filterFn = function(item){
return item > 1;
};
RSVP.filter(promises, filterFn).then(function(result){
// result is [ 2, 3 ]
});
```
If any of the `promises` given to `RSVP.filter` are rejected, the first promise
that is rejected will be given as an argument to the returned promise's
rejection handler. For example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
var filterFn = function(item){
return item > 1;
};
RSVP.filter(promises, filterFn).then(function(array){
// Code here never runs because there are rejected promises!
}, function(reason) {
// reason.message === "2"
});
```
`RSVP.filter` will also wait for any promises returned from `filterFn`.
For instance, you may want to fetch a list of users then return a subset
of those users based on some asynchronous operation:
```javascript
var alice = { name: 'alice' };
var bob = { name: 'bob' };
var users = [ alice, bob ];
var promises = users.map(function(user){
return RSVP.resolve(user);
});
var filterFn = function(user){
// Here, Alice has permissions to create a blog post, but Bob does not.
return getPrivilegesForUser(user).then(function(privs){
return privs.can_create_blog_post === true;
});
};
RSVP.filter(promises, filterFn).then(function(users){
// true, because the server told us only Alice can create a blog post.
users.length === 1;
// false, because Alice is the only user present in `users`
users[0] === bob;
});
```
@method filter
@static
@for RSVP
@param {Array} promises
@param {Function} filterFn - function to be called on each resolved value to
filter the final results.
@param {String} label optional string describing the promise. Useful for
tooling.
@return {Promise}
*/
exports
[
'default'
]
=
function
filter
(
promises
,
filterFn
,
label
)
{
return
Promise
.
all
(
promises
,
label
).
then
(
function
(
values
)
{
if
(
!
isFunction
(
filterFn
))
{
throw
new
TypeError
(
'You must pass a function as filter
\'
s second argument.'
);
}
var
length
=
values
.
length
;
var
filtered
=
new
Array
(
length
);
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
filtered
[
i
]
=
filterFn
(
values
[
i
]);
}
return
Promise
.
all
(
filtered
,
label
).
then
(
function
(
filtered$2
)
{
var
results
=
new
Array
(
length
);
var
newLength
=
0
;
for
(
var
i$2
=
0
;
i$2
<
length
;
i$2
++
)
{
if
(
filtered$2
[
i$2
]
===
true
)
{
results
[
newLength
]
=
values
[
i$2
];
newLength
++
;
}
}
results
.
length
=
newLength
;
return
results
;
});
});
};
},{
"./promise"
:
53
,
"./utils"
:
63
}],
48
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
var
isNonThenable
=
require
(
'./utils'
).
isNonThenable
;
var
keysOf
=
require
(
'./utils'
).
keysOf
;
/**
`RSVP.hashSettled` is similar to `RSVP.allSettled`, but takes an object
instead of an array for its `promises` argument.
Unlike `RSVP.all` or `RSVP.hash`, which implement a fail-fast method,
but like `RSVP.allSettled`, `hashSettled` waits until all the
constituent promises have returned and then shows you all the results
with their states and values/reasons. This is useful if you want to
handle multiple promises' failure states together as a set.
Returns a promise that is fulfilled when all the given promises have been
settled, or rejected if the passed parameters are invalid.
The returned promise is fulfilled with a hash that has the same key names as
the `promises` object argument. If any of the values in the object are not
promises, they will be copied over to the fulfilled object and marked with state
'fulfilled'.
Example:
```javascript
var promises = {
myPromise: RSVP.Promise.resolve(1),
yourPromise: RSVP.Promise.resolve(2),
theirPromise: RSVP.Promise.resolve(3),
notAPromise: 4
};
RSVP.hashSettled(promises).then(function(hash){
// hash here is an object that looks like:
// {
// myPromise: { state: 'fulfilled', value: 1 },
// yourPromise: { state: 'fulfilled', value: 2 },
// theirPromise: { state: 'fulfilled', value: 3 },
// notAPromise: { state: 'fulfilled', value: 4 }
// }
});
```
If any of the `promises` given to `RSVP.hash` are rejected, the state will
be set to 'rejected' and the reason for rejection provided.
Example:
```javascript
var promises = {
myPromise: RSVP.Promise.resolve(1),
rejectedPromise: RSVP.Promise.reject(new Error('rejection')),
anotherRejectedPromise: RSVP.Promise.reject(new Error('more rejection')),
};
RSVP.hashSettled(promises).then(function(hash){
// hash here is an object that looks like:
// {
// myPromise: { state: 'fulfilled', value: 1 },
// rejectedPromise: { state: 'rejected', reason: Error },
// anotherRejectedPromise: { state: 'rejected', reason: Error },
// }
// Note that for rejectedPromise, reason.message == 'rejection',
// and for anotherRejectedPromise, reason.message == 'more rejection'.
});
```
An important note: `RSVP.hashSettled` is intended for plain JavaScript objects that
are just a set of keys and values. `RSVP.hashSettled` will NOT preserve prototype
chains.
Example:
```javascript
function MyConstructor(){
this.example = RSVP.Promise.resolve('Example');
}
MyConstructor.prototype = {
protoProperty: RSVP.Promise.resolve('Proto Property')
};
var myObject = new MyConstructor();
RSVP.hashSettled(myObject).then(function(hash){
// protoProperty will not be present, instead you will just have an
// object that looks like:
// {
// example: { state: 'fulfilled', value: 'Example' }
// }
//
// hash.hasOwnProperty('protoProperty'); // false
// 'undefined' === typeof hash.protoProperty
});
```
@method hashSettled
@for RSVP
@param {Object} promises
@param {String} label optional string that describes the promise.
Useful for tooling.
@return {Promise} promise that is fulfilled when when all properties of `promises`
have been settled.
@static
*/
exports
[
'default'
]
=
function
hashSettled
(
object
,
label
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
results
=
{};
var
keys
=
keysOf
(
object
);
var
remaining
=
keys
.
length
;
var
entry
,
property
;
if
(
remaining
===
0
)
{
resolve
(
results
);
return
;
}
function
fulfilledResolver
(
property$2
)
{
return
function
(
value
)
{
resolveAll
(
property$2
,
fulfilled
(
value
));
};
}
function
rejectedResolver
(
property$2
)
{
return
function
(
reason
)
{
resolveAll
(
property$2
,
rejected
(
reason
));
};
}
function
resolveAll
(
property$2
,
value
)
{
results
[
property$2
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
}
}
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
property
=
keys
[
i
];
entry
=
object
[
property
];
if
(
isNonThenable
(
entry
))
{
resolveAll
(
property
,
fulfilled
(
entry
));
}
else
{
Promise
.
resolve
(
entry
).
then
(
fulfilledResolver
(
property
),
rejectedResolver
(
property
));
}
}
});
};
function
fulfilled
(
value
)
{
return
{
state
:
'fulfilled'
,
value
:
value
};
}
function
rejected
(
reason
)
{
return
{
state
:
'rejected'
,
reason
:
reason
};
}
},{
"./promise"
:
53
,
"./utils"
:
63
}],
49
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
var
isNonThenable
=
require
(
'./utils'
).
isNonThenable
;
var
keysOf
=
require
(
'./utils'
).
keysOf
;
/**
`RSVP.hash` is similar to `RSVP.all`, but takes an object instead of an array
for its `promises` argument.
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The returned promise
is fulfilled with a hash that has the same key names as the `promises` object
argument. If any of the values in the object are not promises, they will
simply be copied over to the fulfilled object.
Example:
```javascript
var promises = {
myPromise: RSVP.resolve(1),
yourPromise: RSVP.resolve(2),
theirPromise: RSVP.resolve(3),
notAPromise: 4
};
RSVP.hash(promises).then(function(hash){
// hash here is an object that looks like:
// {
// myPromise: 1,
// yourPromise: 2,
// theirPromise: 3,
// notAPromise: 4
// }
});
````
If any of the `promises` given to `RSVP.hash` are rejected, the first promise
that is rejected will be given as the reason to the rejection handler.
Example:
```javascript
var promises = {
myPromise: RSVP.resolve(1),
rejectedPromise: RSVP.reject(new Error("rejectedPromise")),
anotherRejectedPromise: RSVP.reject(new Error("anotherRejectedPromise")),
};
RSVP.hash(promises).then(function(hash){
// Code here never runs because there are rejected promises!
}, function(reason) {
// reason.message === "rejectedPromise"
});
```
An important note: `RSVP.hash` is intended for plain JavaScript objects that
are just a set of keys and values. `RSVP.hash` will NOT preserve prototype
chains.
Example:
```javascript
function MyConstructor(){
this.example = RSVP.resolve("Example");
}
MyConstructor.prototype = {
protoProperty: RSVP.resolve("Proto Property")
};
var myObject = new MyConstructor();
RSVP.hash(myObject).then(function(hash){
// protoProperty will not be present, instead you will just have an
// object that looks like:
// {
// example: "Example"
// }
//
// hash.hasOwnProperty('protoProperty'); // false
// 'undefined' === typeof hash.protoProperty
});
```
@method hash
@static
@for RSVP
@param {Object} promises
@param {String} label optional string that describes the promise.
Useful for tooling.
@return {Promise} promise that is fulfilled when all properties of `promises`
have been fulfilled, or rejected if any of them become rejected.
*/
exports
[
'default'
]
=
function
hash
(
object
,
label
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
results
=
{};
var
keys
=
keysOf
(
object
);
var
remaining
=
keys
.
length
;
var
entry
,
property
;
if
(
remaining
===
0
)
{
resolve
(
results
);
return
;
}
function
fulfilledTo
(
property$2
)
{
return
function
(
value
)
{
results
[
property$2
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
}
};
}
function
onRejection
(
reason
)
{
remaining
=
0
;
reject
(
reason
);
}
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
property
=
keys
[
i
];
entry
=
object
[
property
];
if
(
isNonThenable
(
entry
))
{
results
[
property
]
=
entry
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
}
}
else
{
Promise
.
resolve
(
entry
).
then
(
fulfilledTo
(
property
),
onRejection
);
}
}
});
};
},{
"./promise"
:
53
,
"./utils"
:
63
}],
50
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
config
=
require
(
'./config'
).
config
;
var
now
=
require
(
'./utils'
).
now
;
exports
[
'default'
]
=
function
instrument
(
eventName
,
promise
,
child
)
{
// instrumentation should not disrupt normal usage.
try
{
config
.
trigger
(
eventName
,
{
guid
:
promise
.
_guidKey
+
promise
.
_id
,
eventName
:
eventName
,
detail
:
promise
.
_detail
,
childGuid
:
child
&&
promise
.
_guidKey
+
child
.
_id
,
label
:
promise
.
_label
,
timeStamp
:
now
(),
stack
:
new
Error
(
promise
.
_label
).
stack
});
}
catch
(
error
)
{
setTimeout
(
function
()
{
throw
error
;
},
0
);
}
};
},{
"./config"
:
44
,
"./utils"
:
63
}],
51
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
var
isArray
=
require
(
'./utils'
).
isArray
;
var
isFunction
=
require
(
'./utils'
).
isFunction
;
/**
`RSVP.map` is similar to JavaScript's native `map` method, except that it
waits for all promises to become fulfilled before running the `mapFn` on
each item in given to `promises`. `RSVP.map` returns a promise that will
become fulfilled with the result of running `mapFn` on the values the promises
become fulfilled with.
For example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
var mapFn = function(item){
return item + 1;
};
RSVP.map(promises, mapFn).then(function(result){
// result is [ 2, 3, 4 ]
});
```
If any of the `promises` given to `RSVP.map` are rejected, the first promise
that is rejected will be given as an argument to the returned promise's
rejection handler. For example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
var mapFn = function(item){
return item + 1;
};
RSVP.map(promises, mapFn).then(function(array){
// Code here never runs because there are rejected promises!
}, function(reason) {
// reason.message === "2"
});
```
`RSVP.map` will also wait if a promise is returned from `mapFn`. For example,
say you want to get all comments from a set of blog posts, but you need
the blog posts first becuase they contain a url to those comments.
```javscript
var mapFn = function(blogPost){
// getComments does some ajax and returns an RSVP.Promise that is fulfilled
// with some comments data
return getComments(blogPost.comments_url);
};
// getBlogPosts does some ajax and returns an RSVP.Promise that is fulfilled
// with some blog post data
RSVP.map(getBlogPosts(), mapFn).then(function(comments){
// comments is the result of asking the server for the comments
// of all blog posts returned from getBlogPosts()
});
```
@method map
@static
@for RSVP
@param {Array} promises
@param {Function} mapFn function to be called on each fulfilled promise.
@param {String} label optional string for labeling the promise.
Useful for tooling.
@return {Promise} promise that is fulfilled with the result of calling
`mapFn` on each fulfilled promise or value when they become fulfilled.
The promise will be rejected if any of the given `promises` become rejected.
@static
*/
exports
[
'default'
]
=
function
map
(
promises
,
mapFn
,
label
)
{
return
Promise
.
all
(
promises
,
label
).
then
(
function
(
values
)
{
if
(
!
isFunction
(
mapFn
))
{
throw
new
TypeError
(
'You must pass a function as map
\'
s second argument.'
);
}
var
length
=
values
.
length
;
var
results
=
new
Array
(
length
);
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
results
[
i
]
=
mapFn
(
values
[
i
]);
}
return
Promise
.
all
(
results
,
label
);
});
};
},{
"./promise"
:
53
,
"./utils"
:
63
}],
52
:[
function
(
require
,
module
,
exports
){
'use strict'
;
/* global arraySlice */
var
Promise
=
require
(
'./promise'
)[
'default'
];
var
isArray
=
require
(
'./utils'
).
isArray
;
/**
`RSVP.denodeify` takes a "node-style" function and returns a function that
will return an `RSVP.Promise`. You can use `denodeify` in Node.js or the
browser when you'd prefer to use promises over using callbacks. For example,
`denodeify` transforms the following:
```javascript
var fs = require('fs');
fs.readFile('myfile.txt', function(err, data){
if (err) return handleError(err);
handleData(data);
});
```
into:
```javascript
var fs = require('fs');
var readFile = RSVP.denodeify(fs.readFile);
readFile('myfile.txt').then(handleData, handleError);
```
If the node function has multiple success parameters, then `denodeify`
just returns the first one:
```javascript
var request = RSVP.denodeify(require('request'));
request('http://example.com').then(function(res) {
// ...
});
```
However, if you need all success parameters, setting `denodeify`'s
second parameter to `true` causes it to return all success parameters
as an array:
```javascript
var request = RSVP.denodeify(require('request'), true);
request('http://example.com').then(function(result) {
// result[0] -> res
// result[1] -> body
});
```
Or if you pass it an array with names it returns the parameters as a hash:
```javascript
var request = RSVP.denodeify(require('request'), ['res', 'body']);
request('http://example.com').then(function(result) {
// result.res
// result.body
});
```
Sometimes you need to retain the `this`:
```javascript
var app = require('express')();
var render = RSVP.denodeify(app.render.bind(app));
```
The denodified function inherits from the original function. It works in all
environments, except IE 10 and below. Consequently all properties of the original
function are available to you. However, any properties you change on the
denodeified function won't be changed on the original function. Example:
```javascript
var request = RSVP.denodeify(require('request')),
cookieJar = request.jar(); // <- Inheritance is used here
request('http://example.com', {jar: cookieJar}).then(function(res) {
// cookieJar.cookies holds now the cookies returned by example.com
});
```
Using `denodeify` makes it easier to compose asynchronous operations instead
of using callbacks. For example, instead of:
```javascript
var fs = require('fs');
fs.readFile('myfile.txt', function(err, data){
if (err) { ... } // Handle error
fs.writeFile('myfile2.txt', data, function(err){
if (err) { ... } // Handle error
console.log('done')
});
});
```
you can chain the operations together using `then` from the returned promise:
```javascript
var fs = require('fs');
var readFile = RSVP.denodeify(fs.readFile);
var writeFile = RSVP.denodeify(fs.writeFile);
readFile('myfile.txt').then(function(data){
return writeFile('myfile2.txt', data);
}).then(function(){
console.log('done')
}).catch(function(error){
// Handle error
});
```
@method denodeify
@static
@for RSVP
@param {Function} nodeFunc a "node-style" function that takes a callback as
its last argument. The callback expects an error to be passed as its first
argument (if an error occurred, otherwise null), and the value from the
operation as its second argument ("function(err, value){ }").
@param {Boolean|Array} argumentNames An optional paramter that if set
to `true` causes the promise to fulfill with the callback's success arguments
as an array. This is useful if the node function has multiple success
paramters. If you set this paramter to an array with names, the promise will
fulfill with a hash with these names as keys and the success parameters as
values.
@return {Function} a function that wraps `nodeFunc` to return an
`RSVP.Promise`
@static
*/
exports
[
'default'
]
=
function
denodeify
(
nodeFunc
,
argumentNames
)
{
var
asArray
=
argumentNames
===
true
;
var
asHash
=
isArray
(
argumentNames
);
function
denodeifiedFunction
()
{
var
length
=
arguments
.
length
;
var
nodeArgs
=
new
Array
(
length
);
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
nodeArgs
[
i
]
=
arguments
[
i
];
}
var
thisArg
;
if
(
!
asArray
&&
!
asHash
&&
argumentNames
)
{
console
.
warn
(
'Deprecation: RSVP.denodeify() doesn
\'
t allow setting the '
+
'"this" binding anymore. Use yourFunction.bind(yourThis) instead.'
);
thisArg
=
argumentNames
;
}
else
{
thisArg
=
this
;
}
return
Promise
.
all
(
nodeArgs
).
then
(
function
(
nodeArgs$2
)
{
return
new
Promise
(
resolver
);
// sweet.js has a bug, this resolver can't be defined in the constructor
// or the arraySlice macro doesn't work
function
resolver
(
resolve
,
reject
)
{
function
callback
()
{
var
length$2
=
arguments
.
length
;
var
args
=
new
Array
(
length$2
);
for
(
var
i$2
=
0
;
i$2
<
length$2
;
i$2
++
)
{
args
[
i$2
]
=
arguments
[
i$2
];
}
var
error
=
args
[
0
];
var
value
=
args
[
1
];
if
(
error
)
{
reject
(
error
);
}
else
if
(
asArray
)
{
resolve
(
args
.
slice
(
1
));
}
else
if
(
asHash
)
{
var
obj
=
{};
var
successArguments
=
args
.
slice
(
1
);
var
name
;
var
i$3
;
for
(
i$3
=
0
;
i$3
<
argumentNames
.
length
;
i$3
++
)
{
name
=
argumentNames
[
i$3
];
obj
[
name
]
=
successArguments
[
i$3
];
}
resolve
(
obj
);
}
else
{
resolve
(
value
);
}
}
nodeArgs$2
.
push
(
callback
);
nodeFunc
.
apply
(
thisArg
,
nodeArgs$2
);
}
});
}
denodeifiedFunction
.
__proto__
=
nodeFunc
;
return
denodeifiedFunction
;
};
},{
"./promise"
:
53
,
"./utils"
:
63
}],
53
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
config
=
require
(
'./config'
).
config
;
var
EventTarget
=
require
(
'./events'
)[
'default'
];
var
instrument
=
require
(
'./instrument'
)[
'default'
];
var
objectOrFunction
=
require
(
'./utils'
).
objectOrFunction
;
var
isFunction
=
require
(
'./utils'
).
isFunction
;
var
now
=
require
(
'./utils'
).
now
;
var
cast
=
require
(
'./promise/cast'
)[
'default'
];
var
all
=
require
(
'./promise/all'
)[
'default'
];
var
race
=
require
(
'./promise/race'
)[
'default'
];
var
Resolve
=
require
(
'./promise/resolve'
)[
'default'
];
var
Reject
=
require
(
'./promise/reject'
)[
'default'
];
var
guidKey
=
'rsvp_'
+
now
()
+
'-'
;
var
counter
=
0
;
function
noop
()
{
}
exports
[
'default'
]
=
Promise
;
/**
Promise objects represent the eventual result of an asynchronous operation. The
primary way of interacting with a promise is through its `then` method, which
registers callbacks to receive either a promise’s eventual value or the reason
why the promise cannot be fulfilled.
Terminology
-----------
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
- `thenable` is an object or function that defines a `then` method.
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
- `exception` is a value that is thrown using the throw statement.
- `reason` is a value that indicates why a promise was rejected.
- `settled` the final resting state of a promise, fulfilled or rejected.
A promise can be in one of three states: pending, fulfilled, or rejected.
Promises that are fulfilled have a fulfillment value and are in the fulfilled
state. Promises that are rejected have a rejection reason and are in the
rejected state. A fulfillment value is never a thenable.
Promises can also be said to *resolve* a value. If this value is also a
promise, then the original promise's settled state will match the value's
settled state. So a promise that *resolves* a promise that rejects will
itself reject, and a promise that *resolves* a promise that fulfills will
itself fulfill.
Basic Usage:
------------
```js
var promise = new Promise(function(resolve, reject) {
// on success
resolve(value);
// on failure
reject(reason);
});
promise.then(function(value) {
// on fulfillment
}, function(reason) {
// on rejection
});
```
Advanced Usage:
---------------
Promises shine when abstracting away asynchronous interactions such as
`XMLHttpRequest`s.
```js
function getJSON(url) {
return new Promise(function(resolve, reject){
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onreadystatechange = handler;
xhr.responseType = 'json';
xhr.setRequestHeader('Accept', 'application/json');
xhr.send();
function handler() {
if (this.readyState === this.DONE) {
if (this.status === 200) {
resolve(this.response);
} else {
reject(new Error("getJSON: `" + url + "` failed with status: [" + this.status + "]");
}
}
};
});
}
getJSON('/posts.json').then(function(json) {
// on fulfillment
}, function(reason) {
// on rejection
});
```
Unlike callbacks, promises are great composable primitives.
```js
Promise.all([
getJSON('/posts'),
getJSON('/comments')
]).then(function(values){
values[0] // => postsJSON
values[1] // => commentsJSON
return values;
});
```
@class RSVP.Promise
@param {function}
@param {String} label optional string for labeling the promise.
Useful for tooling.
@constructor
*/
function
Promise
(
resolver
,
label
)
{
if
(
!
isFunction
(
resolver
))
{
throw
new
TypeError
(
'You must pass a resolver function as the first argument to the promise constructor'
);
}
if
(
!
(
this
instanceof
Promise
))
{
throw
new
TypeError
(
'Failed to construct
\'
Promise
\'
: Please use the
\'
new
\'
operator, this object constructor cannot be called as a function.'
);
}
this
.
_id
=
counter
++
;
this
.
_label
=
label
;
this
.
_subscribers
=
[];
if
(
config
.
instrument
)
{
instrument
(
'created'
,
this
);
}
if
(
noop
!==
resolver
)
{
invokeResolver
(
resolver
,
this
);
}
}
function
invokeResolver
(
resolver
,
promise
)
{
function
resolvePromise
(
value
)
{
resolve
(
promise
,
value
);
}
function
rejectPromise
(
reason
)
{
reject
(
promise
,
reason
);
}
try
{
resolver
(
resolvePromise
,
rejectPromise
);
}
catch
(
e
)
{
rejectPromise
(
e
);
}
}
Promise
.
cast
=
cast
;
Promise
.
all
=
all
;
Promise
.
race
=
race
;
Promise
.
resolve
=
Resolve
;
Promise
.
reject
=
Reject
;
var
PENDING
=
void
0
;
var
SEALED
=
0
;
var
FULFILLED
=
1
;
var
REJECTED
=
2
;
function
subscribe
(
parent
,
child
,
onFulfillment
,
onRejection
)
{
var
subscribers
=
parent
.
_subscribers
;
var
length
=
subscribers
.
length
;
subscribers
[
length
]
=
child
;
subscribers
[
length
+
FULFILLED
]
=
onFulfillment
;
subscribers
[
length
+
REJECTED
]
=
onRejection
;
}
function
publish
(
promise
,
settled
)
{
var
child
,
callback
,
subscribers
=
promise
.
_subscribers
,
detail
=
promise
.
_detail
;
if
(
config
.
instrument
)
{
instrument
(
settled
===
FULFILLED
?
'fulfilled'
:
'rejected'
,
promise
);
}
for
(
var
i
=
0
;
i
<
subscribers
.
length
;
i
+=
3
)
{
child
=
subscribers
[
i
];
callback
=
subscribers
[
i
+
settled
];
invokeCallback
(
settled
,
child
,
callback
,
detail
);
}
promise
.
_subscribers
=
null
;
}
Promise
.
prototype
=
{
constructor
:
Promise
,
_id
:
undefined
,
_guidKey
:
guidKey
,
_label
:
undefined
,
_state
:
undefined
,
_detail
:
undefined
,
_subscribers
:
undefined
,
_onerror
:
function
(
reason
)
{
config
.
trigger
(
'error'
,
reason
);
},
then
:
function
(
onFulfillment
,
onRejection
,
label
)
{
var
promise
=
this
;
this
.
_onerror
=
null
;
var
thenPromise
=
new
this
.
constructor
(
noop
,
label
);
if
(
this
.
_state
)
{
var
callbacks
=
arguments
;
config
.
async
(
function
invokePromiseCallback
()
{
invokeCallback
(
promise
.
_state
,
thenPromise
,
callbacks
[
promise
.
_state
-
1
],
promise
.
_detail
);
});
}
else
{
subscribe
(
this
,
thenPromise
,
onFulfillment
,
onRejection
);
}
if
(
config
.
instrument
)
{
instrument
(
'chained'
,
promise
,
thenPromise
);
}
return
thenPromise
;
},
'catch'
:
function
(
onRejection
,
label
)
{
return
this
.
then
(
null
,
onRejection
,
label
);
},
'finally'
:
function
(
callback
,
label
)
{
var
constructor
=
this
.
constructor
;
return
this
.
then
(
function
(
value
)
{
return
constructor
.
resolve
(
callback
()).
then
(
function
()
{
return
value
;
});
},
function
(
reason
)
{
return
constructor
.
resolve
(
callback
()).
then
(
function
()
{
throw
reason
;
});
},
label
);
}
};
function
invokeCallback
(
settled
,
promise
,
callback
,
detail
)
{
var
hasCallback
=
isFunction
(
callback
),
value
,
error
,
succeeded
,
failed
;
if
(
hasCallback
)
{
try
{
value
=
callback
(
detail
);
succeeded
=
true
;
}
catch
(
e
)
{
failed
=
true
;
error
=
e
;
}
}
else
{
value
=
detail
;
succeeded
=
true
;
}
if
(
handleThenable
(
promise
,
value
))
{
return
;
}
else
if
(
hasCallback
&&
succeeded
)
{
resolve
(
promise
,
value
);
}
else
if
(
failed
)
{
reject
(
promise
,
error
);
}
else
if
(
settled
===
FULFILLED
)
{
resolve
(
promise
,
value
);
}
else
if
(
settled
===
REJECTED
)
{
reject
(
promise
,
value
);
}
}
function
handleThenable
(
promise
,
value
)
{
var
then
=
null
,
resolved
;
try
{
if
(
promise
===
value
)
{
throw
new
TypeError
(
'A promises callback cannot return that same promise.'
);
}
if
(
objectOrFunction
(
value
))
{
then
=
value
.
then
;
if
(
isFunction
(
then
))
{
then
.
call
(
value
,
function
(
val
)
{
if
(
resolved
)
{
return
true
;
}
resolved
=
true
;
if
(
value
!==
val
)
{
resolve
(
promise
,
val
);
}
else
{
fulfill
(
promise
,
val
);
}
},
function
(
val
)
{
if
(
resolved
)
{
return
true
;
}
resolved
=
true
;
reject
(
promise
,
val
);
},
'Settle: '
+
(
promise
.
_label
||
' unknown promise'
));
return
true
;
}
}
}
catch
(
error
)
{
if
(
resolved
)
{
return
true
;
}
reject
(
promise
,
error
);
return
true
;
}
return
false
;
}
function
resolve
(
promise
,
value
)
{
if
(
promise
===
value
)
{
fulfill
(
promise
,
value
);
}
else
if
(
!
handleThenable
(
promise
,
value
))
{
fulfill
(
promise
,
value
);
}
}
function
fulfill
(
promise
,
value
)
{
if
(
promise
.
_state
!==
PENDING
)
{
return
;
}
promise
.
_state
=
SEALED
;
promise
.
_detail
=
value
;
config
.
async
(
publishFulfillment
,
promise
);
}
function
reject
(
promise
,
reason
)
{
if
(
promise
.
_state
!==
PENDING
)
{
return
;
}
promise
.
_state
=
SEALED
;
promise
.
_detail
=
reason
;
config
.
async
(
publishRejection
,
promise
);
}
function
publishFulfillment
(
promise
)
{
publish
(
promise
,
promise
.
_state
=
FULFILLED
);
}
function
publishRejection
(
promise
)
{
if
(
promise
.
_onerror
)
{
promise
.
_onerror
(
promise
.
_detail
);
}
publish
(
promise
,
promise
.
_state
=
REJECTED
);
}
},{
"./config"
:
44
,
"./events"
:
46
,
"./instrument"
:
50
,
"./promise/all"
:
54
,
"./promise/cast"
:
55
,
"./promise/race"
:
56
,
"./promise/reject"
:
57
,
"./promise/resolve"
:
58
,
"./utils"
:
63
}],
54
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
isArray
=
require
(
'../utils'
).
isArray
;
var
isNonThenable
=
require
(
'../utils'
).
isNonThenable
;
/**
`RSVP.Promise.all` accepts an array of promises, and returns a new promise which
is fulfilled with an array of fulfillment values for the passed promises, or
rejected with the reason of the first passed promise to be rejected. It casts all
elements of the passed iterable to promises as it runs this algorithm.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.Promise.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.Promise.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@static
@param {Array} entries array of promises
@param {String} label optional string for labeling the promise.
Useful for tooling.
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
@static
*/
exports
[
'default'
]
=
function
all
(
entries
,
label
)
{
/*jshint validthis:true */
var
Constructor
=
this
;
return
new
Constructor
(
function
(
resolve
,
reject
)
{
if
(
!
isArray
(
entries
))
{
throw
new
TypeError
(
'You must pass an array to all.'
);
}
var
remaining
=
entries
.
length
;
var
results
=
new
Array
(
remaining
);
var
entry
,
pending
=
true
;
if
(
remaining
===
0
)
{
resolve
(
results
);
return
;
}
function
fulfillmentAt
(
index$2
)
{
return
function
(
value
)
{
results
[
index$2
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
}
};
}
function
onRejection
(
reason
)
{
remaining
=
0
;
reject
(
reason
);
}
for
(
var
index
=
0
;
index
<
entries
.
length
;
index
++
)
{
entry
=
entries
[
index
];
if
(
isNonThenable
(
entry
))
{
results
[
index
]
=
entry
;
if
(
--
remaining
===
0
)
{
resolve
(
results
);
}
}
else
{
Constructor
.
resolve
(
entry
).
then
(
fulfillmentAt
(
index
),
onRejection
);
}
}
},
label
);
};
},{
"../utils"
:
63
}],
55
:[
function
(
require
,
module
,
exports
){
'use strict'
;
/**
@deprecated
`RSVP.Promise.cast` coerces its argument to a promise, or returns the
argument if it is already a promise which shares a constructor with the caster.
Example:
```javascript
var promise = RSVP.Promise.resolve(1);
var casted = RSVP.Promise.cast(promise);
console.log(promise === casted); // true
```
In the case of a promise whose constructor does not match, it is assimilated.
The resulting promise will fulfill or reject based on the outcome of the
promise being casted.
Example:
```javascript
var thennable = $.getJSON('/api/foo');
var casted = RSVP.Promise.cast(thennable);
console.log(thennable === casted); // false
console.log(casted instanceof RSVP.Promise) // true
casted.then(function(data) {
// data is the value getJSON fulfills with
});
```
In the case of a non-promise, a promise which will fulfill with that value is
returned.
Example:
```javascript
var value = 1; // could be a number, boolean, string, undefined...
var casted = RSVP.Promise.cast(value);
console.log(value === casted); // false
console.log(casted instanceof RSVP.Promise) // true
casted.then(function(val) {
val === value // => true
});
```
`RSVP.Promise.cast` is similar to `RSVP.Promise.resolve`, but `RSVP.Promise.cast` differs in the
following ways:
* `RSVP.Promise.cast` serves as a memory-efficient way of getting a promise, when you
have something that could either be a promise or a value. RSVP.resolve
will have the same effect but will create a new promise wrapper if the
argument is a promise.
* `RSVP.Promise.cast` is a way of casting incoming thenables or promise subclasses to
promises of the exact class specified, so that the resulting object's `then` is
ensured to have the behavior of the constructor you are calling cast on (i.e., RSVP.Promise).
@method cast
@static
@param {Object} object to be casted
@param {String} label optional string for labeling the promise.
Useful for tooling.
@return {Promise} promise
*/
exports
[
'default'
]
=
function
cast
(
object
,
label
)
{
/*jshint validthis:true */
var
Constructor
=
this
;
if
(
object
&&
typeof
object
===
'object'
&&
object
.
constructor
===
Constructor
)
{
return
object
;
}
return
new
Constructor
(
function
(
resolve
)
{
resolve
(
object
);
},
label
);
};
},{}],
56
:[
function
(
require
,
module
,
exports
){
'use strict'
;
/* global toString */
var
isArray
=
require
(
'../utils'
).
isArray
;
var
isFunction
=
require
(
'../utils'
).
isFunction
;
var
isNonThenable
=
require
(
'../utils'
).
isNonThenable
;
/**
`RSVP.Promise.race` returns a new promise which is settled in the same way as the
first passed promise to settle.
Example:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 1");
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 2");
}, 100);
});
RSVP.Promise.race([promise1, promise2]).then(function(result){
// result === "promise 2" because it was resolved before promise1
// was resolved.
});
```
`RSVP.Promise.race` is deterministic in that only the state of the first
settled promise matters. For example, even if other promises given to the
`promises` array argument are resolved, but the first settled promise has
become rejected before the other promises became fulfilled, the returned
promise will become rejected:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 1");
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
reject(new Error("promise 2"));
}, 100);
});
RSVP.Promise.race([promise1, promise2]).then(function(result){
// Code here never runs
}, function(reason){
// reason.message === "promise2" because promise 2 became rejected before
// promise 1 became fulfilled
});
```
An example real-world use case is implementing timeouts:
```javascript
RSVP.Promise.race([ajax('foo.json'), timeout(5000)])
```
@method race
@static
@param {Array} promises array of promises to observe
@param {String} label optional string for describing the promise returned.
Useful for tooling.
@return {Promise} a promise which settles in the same way as the first passed
promise to settle.
*/
exports
[
'default'
]
=
function
race
(
entries
,
label
)
{
/*jshint validthis:true */
var
Constructor
=
this
,
entry
;
return
new
Constructor
(
function
(
resolve
,
reject
)
{
if
(
!
isArray
(
entries
))
{
throw
new
TypeError
(
'You must pass an array to race.'
);
}
var
pending
=
true
;
function
onFulfillment
(
value
)
{
if
(
pending
)
{
pending
=
false
;
resolve
(
value
);
}
}
function
onRejection
(
reason
)
{
if
(
pending
)
{
pending
=
false
;
reject
(
reason
);
}
}
for
(
var
i
=
0
;
i
<
entries
.
length
;
i
++
)
{
entry
=
entries
[
i
];
if
(
isNonThenable
(
entry
))
{
pending
=
false
;
resolve
(
entry
);
return
;
}
else
{
Constructor
.
resolve
(
entry
).
then
(
onFulfillment
,
onRejection
);
}
}
},
label
);
};
},{
"../utils"
:
63
}],
57
:[
function
(
require
,
module
,
exports
){
'use strict'
;
/**
`RSVP.Promise.reject` returns a promise rejected with the passed `reason`.
It is shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.Promise.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@static
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise rejected with the given `reason`.
*/
exports
[
'default'
]
=
function
reject
(
reason
,
label
)
{
/*jshint validthis:true */
var
Constructor
=
this
;
return
new
Constructor
(
function
(
resolve
,
reject$2
)
{
reject$2
(
reason
);
},
label
);
};
},{}],
58
:[
function
(
require
,
module
,
exports
){
'use strict'
;
/**
`RSVP.Promise.resolve` returns a promise that will become resolved with the
passed `value`. It is shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
resolve(1);
});
promise.then(function(value){
// value === 1
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.Promise.resolve(1);
promise.then(function(value){
// value === 1
});
```
@method resolve
@static
@param {Any} value value that the returned promise will be resolved with
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become fulfilled with the given
`value`
*/
exports
[
'default'
]
=
function
resolve
(
object
,
label
)
{
/*jshint validthis:true */
var
Constructor
=
this
;
if
(
object
&&
typeof
object
===
'object'
&&
object
.
constructor
===
Constructor
)
{
return
object
;
}
return
new
Constructor
(
function
(
resolve$2
)
{
resolve$2
(
object
);
},
label
);
};
},{}],
59
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
/**
This is a convenient alias for `RSVP.Promise.race`.
@method race
@static
@for RSVP
@param {Array} array Array of promises.
@param {String} label An optional label. This is useful
for tooling.
*/
exports
[
'default'
]
=
function
race
(
array
,
label
)
{
return
Promise
.
race
(
array
,
label
);
};
},{
"./promise"
:
53
}],
60
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
/**
This is a convenient alias for `RSVP.Promise.reject`.
@method reject
@static
@for RSVP
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise rejected with the given `reason`.
*/
exports
[
'default'
]
=
function
reject
(
reason
,
label
)
{
return
Promise
.
reject
(
reason
,
label
);
};
},{
"./promise"
:
53
}],
61
:[
function
(
require
,
module
,
exports
){
'use strict'
;
var
Promise
=
require
(
'./promise'
)[
'default'
];
/**
This is a convenient alias for `RSVP.Promise.resolve`.
@method resolve
@static
@for RSVP
@param {Any} value value that the returned promise will be resolved with
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become fulfilled with the given
`value`
*/
exports
[
'default'
]
=
function
resolve
(
value
,
label
)
{
return
Promise
.
resolve
(
value
,
label
);
};
},{
"./promise"
:
53
}],
62
:[
function
(
require
,
module
,
exports
){
'use strict'
;
/**
`RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event
loop in order to aid debugging.
Promises A+ specifies that any exceptions that occur with a promise must be
caught by the promises implementation and bubbled to the last handler. For
this reason, it is recommended that you always specify a second rejection
handler function to `then`. However, `RSVP.rethrow` will throw the exception
outside of the promise, so it bubbles up to your console if in the browser,
or domain/cause uncaught exception in Node. `rethrow` will also throw the
error again so the error can be handled by the promise per the spec.
```javascript
function throws(){
throw new Error('Whoops!');
}
var promise = new RSVP.Promise(function(resolve, reject){
throws();
});
promise.catch(RSVP.rethrow).then(function(){
// Code here doesn't run because the promise became rejected due to an
// error!
}, function (err){
// handle the error here
});
```
The 'Whoops' error will be thrown on the next turn of the event loop
and you can watch for it in your console. You can also handle it using a
rejection handler given to `.then` or `.catch` on the returned promise.
@method rethrow
@static
@for RSVP
@param {Error} reason reason the promise became rejected.
@throws Error
@static
*/
exports
[
'default'
]
=
function
rethrow
(
reason
)
{
setTimeout
(
function
()
{
throw
reason
;
});
throw
reason
;
};
},{}],
63
:[
function
(
require
,
module
,
exports
){
'use strict'
;
function
objectOrFunction
(
x
)
{
return
typeof
x
===
'function'
||
typeof
x
===
'object'
&&
x
!==
null
;
}
exports
.
objectOrFunction
=
objectOrFunction
;
function
isFunction
(
x
)
{
return
typeof
x
===
'function'
;
}
exports
.
isFunction
=
isFunction
;
function
isNonThenable
(
x
)
{
return
!
objectOrFunction
(
x
);
}
exports
.
isNonThenable
=
isNonThenable
;
var
_isArray
;
if
(
!
Array
.
isArray
)
{
_isArray
=
function
(
x
)
{
return
Object
.
prototype
.
toString
.
call
(
x
)
===
'[object Array]'
;
};
}
else
{
_isArray
=
Array
.
isArray
;
}
var
isArray
=
_isArray
;
exports
.
isArray
=
isArray
;
// Date.now is not available in browsers < IE9
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility
var
now
=
Date
.
now
||
function
()
{
return
new
Date
().
getTime
();
};
exports
.
now
=
now
;
var
keysOf
=
Object
.
keys
||
function
(
object
)
{
var
result
=
[];
for
(
var
prop
in
object
)
{
result
.
push
(
prop
);
}
return
result
;
};
exports
.
keysOf
=
keysOf
;
},{}],
"./psd/init.coffee"
:[
function
(
require
,
module
,
exports
){
},{}],
"./psd/init.coffee"
:[
function
(
require
,
module
,
exports
){
module
.
exports
=
require
(
'/ioUh4'
);
module
.
exports
=
require
(
'/ioUh4'
);
},{}],
"/ioUh4"
:[
function
(
require
,
module
,
exports
){
},{}],
"/ioUh4"
:[
function
(
require
,
module
,
exports
){
var
RSVP
;
RSVP
=
require
(
'rsvp'
);
module
.
exports
=
{
module
.
exports
=
{
extended
:
function
(
PSD
)
{
extended
:
function
(
PSD
)
{
return
this
.
fromURL
=
function
(
url
)
{};
return
this
.
fromURL
=
function
(
url
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
var
xhr
;
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"GET"
,
url
,
true
);
xhr
.
responseType
=
"arraybuffer"
;
xhr
.
onload
=
function
()
{
var
data
,
psd
;
data
=
new
Uint8Array
(
xhr
.
response
||
xhr
.
mozResponseArrayBuffer
);
psd
=
new
PSD
(
data
);
return
resolve
(
psd
);
};
return
xhr
.
send
(
null
);
});
};
}
}
};
};
},{}],
"./image_exports/png.coffee"
:[
function
(
require
,
module
,
exports
){
},{
"rsvp"
:
40
}],
"bZ5QlH"
:[
function
(
require
,
module
,
exports
){
module
.
exports
=
require
(
'bZ5QlH'
);
},{}],
"bZ5QlH"
:[
function
(
require
,
module
,
exports
){
module
.
exports
=
{
module
.
exports
=
{
toPng
:
function
()
{
toPng
:
function
()
{
return
new
RSVP
.
Promise
((
function
(
_this
)
{
return
new
RSVP
.
Promise
((
function
(
_this
)
{
...
@@ -8926,4 +10890,6 @@ module.exports = {
...
@@ -8926,4 +10890,6 @@ module.exports = {
};
};
},{}],
"./image_exports/png.coffee"
:[
function
(
require
,
module
,
exports
){
module
.
exports
=
require
(
'bZ5QlH'
);
},{}]},{},[
1
])
},{}]},{},[
1
])
\ No newline at end of file
lib/psd/descriptor.coffee
View file @
fe58a3f6
...
@@ -7,7 +7,7 @@ module.exports = class Descriptor
...
@@ -7,7 +7,7 @@ module.exports = class Descriptor
numItems
=
@
file
.
readInt
()
numItems
=
@
file
.
readInt
()
for
i
in
[
0
...
numItems
]
for
i
in
[
0
...
numItems
]
id
,
value
=
@
parseKeyItem
()
[
id
,
value
]
=
@
parseKeyItem
()
@
data
[
id
]
=
value
@
data
[
id
]
=
value
@
data
@
data
...
@@ -23,7 +23,7 @@ module.exports = class Descriptor
...
@@ -23,7 +23,7 @@ module.exports = class Descriptor
parseKeyItem
:
->
parseKeyItem
:
->
id
=
@
parseId
()
id
=
@
parseId
()
value
=
@
parseItem
()
value
=
@
parseItem
()
return
id
,
value
return
[
id
,
value
]
parseItem
:
(
type
=
null
)
->
parseItem
:
(
type
=
null
)
->
type
=
@
file
.
readString
(
4
)
unless
type
?
type
=
@
file
.
readString
(
4
)
unless
type
?
...
@@ -94,3 +94,58 @@ module.exports = class Descriptor
...
@@ -94,3 +94,58 @@ module.exports = class Descriptor
items
items
parseObjectArray
:
->
parseObjectArray
:
->
throw
"Descriptor object array not implemented yet @
#{
@
file
.
tell
()
}
"
parseRawData
:
->
len
=
@
file
.
readInt
()
@
file
.
read
(
len
)
parseReference
:
->
numItems
=
@
file
.
readInt
()
items
=
[]
for
i
in
[
0
...
numItems
]
type
=
@
file
.
readString
(
4
)
value
=
switch
type
when
'prop'
then
@
parseProperty
()
when
'Clss'
then
@
parseClass
()
when
'Enmr'
then
@
parseEnumReference
()
when
'Idnt'
then
@
parseIdentifier
()
when
'indx'
then
@
parseIndex
()
when
'name'
then
@
file
.
readUnicodeString
()
when
'rele'
then
@
parseOffset
()
items
.
push
type
:
type
,
value
:
value
items
parseUnitDouble
:
->
unitId
=
@
file
.
readString
(
4
)
unit
=
switch
unitId
when
'#Ang'
then
'Angle'
when
'#Rsl'
then
'Density'
when
'#Rlt'
then
'Distance'
when
'#Nne'
then
'None'
when
'#Prc'
then
'Percent'
when
'#Pxl'
then
'Pixels'
when
'#Mlm'
then
'Millimeters'
when
'#Pnt'
then
'Points'
value
=
@
file
.
readDouble
()
id
:
unitId
,
unit
:
unit
,
value
:
value
parseUnitFloat
:
->
unitId
=
@
file
.
readString
(
4
)
unit
=
switch
unitId
when
'#Ang'
then
'Angle'
when
'#Rsl'
then
'Density'
when
'#Rlt'
then
'Distance'
when
'#Nne'
then
'None'
when
'#Prc'
then
'Percent'
when
'#Pxl'
then
'Pixels'
when
'#Mlm'
then
'Millimeters'
when
'#Pnt'
then
'Points'
value
=
@
file
.
readFloat
()
id
:
unitId
,
unit
:
unit
,
value
:
value
\ No newline at end of file
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