Permalink
Browse files

Not using hooks after all

  • Loading branch information...
1 parent 2e20cb0 commit a07e3baf5aee1b4ebf603662d07faea0044d1c97 @assaf committed Nov 22, 2012
Showing with 39 additions and 94 deletions.
  1. +39 −0 doc/new-browser.md
  2. +0 −6 doc/new-events.md
  3. +0 −1 lib/zombie/browser.coffee
  4. +0 −87 lib/zombie/hooks.coffee
View
@@ -0,0 +1,39 @@
+
+
+`browser.assert`
+
+Methods for making assertions against the browser, such as
+`browser.assert.element(".foo")`.
+
+See *Assertions* section for detailed discussion.
+
+
+`browser.console`
+
+Provides access to the browser console (same as `window.console`).
+
+
+`browser.referer`
+
+You can use this to set the HTTP Referer header.
+
+
+`browser.resources`
+
+Access to history of retrieved resources. Also provides methods for retrieving
+resources and managing the resource pipeline. When things are not going your
+way, try calling `browser.resources.dump()`.
+
+See *Resources* section for detailed discussion.
+
+
+`browser.tabs`
+
+Array of all open tabs (windows). Allows you to operate on more than one open
+window at a time.
+
+See *Tabs* section for detailed discussion.
+
+
+`browser.eventLoop`
+`browser.errors`
View
@@ -80,15 +80,9 @@ Emitted whenever a DOM event is fired on the target element, document or window.
The browser now acts as an EventEmitter and windows report a variety of events:
-loading - document is loading into window
-loaded - document loaded
-missing - document not found
-event - event fired on the window/document
error - error reported
executed - script executed
prompt - user was prompted (alert, confirm, prompt)
-storage - change to local or session storage
-cookie - change to a cookie value
xhr - XHR state change (open, loading and loaded)
timeout - timeout or interval fired
submit - form submitted
@@ -11,7 +11,6 @@ Cookies = require("./cookies")
EventLoop = require("./eventloop")
{ format } = require("util")
File = require("fs")
-Hooks = require("./hooks")
{ HTML5 } = require("html5")
Interact = require("./interact")
HTML = require("jsdom").dom.level3.html
View
@@ -1,87 +0,0 @@
-# Hooks provide an easy extensibility mechanism that lets you mess with the
-# browser in various interesting ways.
-
-
-class Hooks
- constructor: (browser)->
- @_hooks = {}
- for name, hooks of globalHooks
- @_hooks[name] = hooks.slice()
-
- # Same as addHook.
- on: (name, fn)->
- @addHook(name, fn)
-
- # Add a function to this browser's hook. The function will be called with
- # list of arguments (depends on the hook) and next hook.
- addHook: (name, fn)->
- unless typeof(fn) == "function" && fn.length > 0
- throw new Error("Expecting second argument to be a function that accepts one or more arguments")
- hooks = @_hooks[name]
- unless hooks
- @_hooks[name] = hooks = []
- hooks.push(fn)
- return
-
- # Removes a function from the hook.
- removeHook: (name, fn)->
- if hooks = @_hooks[name]
- index = hooks.indexOf(fn)
- if ~index
- hooks.splice(index, 1)
- return
-
- # Returns all functions associated with the given hook name.
- hooks: (name)->
- if hooks = @_hooks[name]
- return hooks.slice()
- else
- return []
-
- # Run all functions for the named hook with the supplied aguments. Returns
- # the result of the first function.
- #
- # For example:
- # run("loaded", browser, document)
- run: (name, args...)->
- hooks = @hooks(name)
- index = 0
- callNextFunction = ->
- nextFunction = hooks[index]
- index++
- if nextFunction
- return nextFunction(args..., callNextFunction)
- else
- return null
- return callNextFunction()
-
-
-# Hook chains added to all browsers.
-globalHooks = {}
-
-# Adds a function to all browsers' hook.
-Hooks.addHook = (name, fn)->
- hooks = globalHooks[name]
- unless hooks
- globalHooks[name] = hooks = []
- hooks.push(fn)
- return
-
-# Removes a function from all browsers' hook.
-Hooks.removeHook = (name, fn)->
- hooks = globalHooks[name]
- if hooks
- index = hooks.indexOf(fn)
- if ~index
- hooks.splice(index, 1)
- return
-
-# Returns all functions associated with the given hook name.
-Hooks.hooks = (name)->
- if hooks = globalHooks[name]
- return hooks.slice()
- else
- return []
-
-
-module.exports = Hooks

0 comments on commit a07e3ba

Please sign in to comment.