-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-iced-patch.iced
More file actions
56 lines (43 loc) · 1.4 KB
/
parse-iced-patch.iced
File metadata and controls
56 lines (43 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
( ->
promiseToIcedDeferral = (object, funcName) ->
overridenFunc = object[funcName]
newFunc = ->
args = [].slice.call arguments
cb = args.pop()
promise = overridenFunc.apply this, args
promise.then (result) ->
cb result, undefined
, (error) ->
cb undefined, error
object[funcName+'X'] = newFunc
optionsToIcedDeferral = (object, funcName) ->
overridenFunc = object[funcName]
newFunc = ->
args = [].slice.call arguments
cb = args.pop()
options = undefined
if args.length > 0
options = args.pop()
if options is undefined or options.constructor isnt Object
# not an option hash, push it back
args.push options
options = undefined
options = {} if options is undefined
options.success = (result) ->
cb result, undefined
options.error = (error) ->
cb undefined, error
args.push options
overridenFunc.apply this, args
object[funcName+'X'] = newFunc
['count', 'each', 'find', 'first'].forEach (funcName) ->
promiseToIcedDeferral Parse.Query.prototype, funcName
['destroy', 'fetch', 'save'].forEach (funcName) ->
promiseToIcedDeferral Parse.Object.prototype, funcName
['destroyAll'].forEach (funcName) ->
promiseToIcedDeferral Parse.Object, funcName
['get'].forEach (funcName) ->
optionsToIcedDeferral Parse.Query.prototype, funcName
['saveAll'].forEach (funcName) ->
optionsToIcedDeferral Parse.Object, funcName
)()