-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
521 additions
and
1,438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,45 @@ | ||
{Sync, MakeSync} = require('make-sync') | ||
{sync, makeSync} = require('make-sync') | ||
phantom = require 'phantom' | ||
_ = require 'underscore' | ||
|
||
buildObjectOptions = (options) -> | ||
objectOptions = | ||
create: | ||
mode: options.mode | ||
mode: 'sync' | ||
'sync-return': 'res' | ||
ph: | ||
mode: options.mode | ||
mode: 'sync' | ||
exclude: [/^_/, 'exit'] | ||
'sync-return': 'res' | ||
num_of_args: | ||
set: 2 | ||
page: | ||
mode: options.mode | ||
mode: 'sync' | ||
exclude: [/^_/, 'sendEvent'] | ||
'sync-return': 'res' | ||
num_of_args: | ||
set: 2 | ||
|
||
# Builds replacement for the phantom.create method | ||
createReplacement = (options) -> | ||
objectOptions = buildObjectOptions options | ||
replacement = (args..., done) -> | ||
# disassembling and rebuilding child object structure | ||
# with sync version of objects | ||
phantom.create args..., (ph) -> | ||
_createPage = ph.createPage | ||
ph.createPage = (args..., done) -> | ||
_createPage args..., (page) -> | ||
_evaluate = page.evaluate | ||
_evaluateSync = MakeSync _evaluate , | ||
mode:'sync', | ||
'sync-return': 'res' | ||
MakeSync page, objectOptions.page | ||
if _.isEqual options.mode, ['mixed','args'] | ||
page.evaluate = (args...) -> | ||
[f,fargs...,cb] = args | ||
if (typeof cb) isnt 'function' | ||
fargs.push cb | ||
cb = null | ||
|
||
unless (typeof cb) is 'function' | ||
return _evaluateSync.apply page, args | ||
else | ||
return _evaluate.apply page, args | ||
done page | ||
MakeSync ph, objectOptions.ph | ||
done(ph) | ||
MakeSync replacement, objectOptions.create | ||
|
||
class Phantom | ||
constructor: (options) -> | ||
options = {mode: 'sync'} unless options? | ||
@create = createReplacement options | ||
|
||
exports.Phantom = Phantom | ||
exports.Sync= Sync | ||
_create = (args..., done) -> | ||
# disassembling and rebuilding child object structure | ||
# with sync version of objects | ||
phantom.create args..., (ph) -> | ||
_createPage = ph.createPage | ||
ph.createPage = (args..., done) -> | ||
_createPage args..., (page) -> | ||
_evaluate = page.evaluate | ||
_evaluateSync = makeSync _evaluate , | ||
mode:'sync', | ||
'sync-return': 'res' | ||
makeSync page, objectOptions.page | ||
done page | ||
makeSync ph, objectOptions.ph | ||
done(ph) | ||
|
||
_create = makeSync _create, objectOptions.create | ||
|
||
phantomSync = | ||
phantom: | ||
create: _create | ||
sync: sync | ||
|
||
module.exports = phantomSync | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.