Guide:Hooks

From IokeWiki
Revision as of 21:56, 22 December 2009 by Olabini (talk | contribs) (New page: = Hooks = Sometimes it can be very useful to have one object observe another object. In Ioke this is done using Hooks. One hook can be created indirectly. One hook can also be connected t...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Hooks

Sometimes it can be very useful to have one object observe another object. In Ioke this is done using Hooks. One hook can be created indirectly. One hook can also be connected to several objects. The way a Hook works is that you define methods that will be called for anything that the hook should be interested in.

The main way to create a hook is to use the into method. You can also use the hook! method to add a new observed object to a hook.

x = Origin mimic

; creating a new hook
hook_x = Hook into(x)

y = Origin mimic

; adding a new observed object to a hook:
hook_x hook!(y)

; see all the connected objects:
hook_x connectedObjects should == [x, y]

You can define different methods to specify what events you are interested in. These are:

  • cellAdded
  • cellRemoved
  • cellChanged
  • cellUndefined
  • mimicAdded
  • mimicRemoved
  • mimicked
  • mimicsChanged