-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Conversation
* added phantom.ctx map to persist context across page loads (like state but map is more flexible) * added phantom.addCtxVar() to more easily modify context (instead of whole map replacement) * added optional extra callback parameter to phantom.open() to provide callback function for new page * changed default behavior to exit by default (to not exit, return a negative exit code) * added ability to set exit code by using return rather than exit * added .gitignore file * fixed examples (because of exit code and automatic closure)
Hi Diego, Thank you so much for your contributions. Here are some (mostly minor) comments. Generally it is preferable to have separate small commits for each individual change, as opposed to one big commit that contains everything. For storing object, I consider extending phantom.state to support object persistence (vs only string storage). See http://code.google.com/p/phantomjs/issues/detail?id=34. I believe this would result in cleaner code. The callback approach for open is definitely something I really like! I consider this is the sanest approach to help solving both http://code.google.com/p/phantomjs/issues/detail?id=32 and http://code.google.com/p/phantomjs/issues/detail?id=41. I also agree that phantom.exit might not be always necessary. However, it's still useful in a situation where you want to exit the application from a scoped function, e.g. a callback (because 'return' there will just return from the callback function and not the application). |
Hi. I agree with Ariya: this patch maybe should be split into 2/3 different smaller patches, to make integration easier and clearer. A part from that:
@diegone: looking forward to see this in. |
The open(address, callback) is now implemented in slightly different way. Thanks! |
Hi Ariya,
first of all thanks for sharing this project. Very very cool and useful.
I hacked around it a little bit to try to make it a little more user friendly and you're welcome to pull my changes if you like.
The main change I wanted to make was to use a callback-style programming model instead of the state machine. Now you can pass a callback as a second parameter of open() and don't have to worry about changing and checking the state.
I also wanted to reverse the exit logic to a more natural "exit unless I tell you so" instead of hanging by default. So now calling exit() is not necessary unless we're in an infinite loop and really want to exit. To change the exit code return can be used. To prevent from exiting, returning a negative value will do the trick.
Other minor changes are:
I tried to keep it as backwards compatible as possible but the logic about exit and closure are slightly incompatible in some cases so I also fixed the broken examples. (although I didn't refactor/optimize them)
I also created a new "local weather" example combining 3 of the other examples to show the use of callbacks and context.
Cheers,
Diego