sork/rekapi — pull request #1 by sork (2012-06-07 22:23:10+00:00)
Title: Move canvas-related code from core to the canvas extension

This is a work-in-progress pull request implementing API changes discussed in issue #16.

Among commits, for quicker review, you should look mainly at:
- aa899df5 which contains the main refactoring of Rekapi core and the canvas extension
- c6750549 which fixes an issue with `redraw` due to my changes
- 4bd771fa in which I added the `removeActor` event firing

In other commits, I also updated all the tests, docs examples and the sandbox, so that they reflect the new API. The actual documentation was **not** updated yet, because I'm waiting for you to review everything before I proceed with updating it.

---------

Here is a quick summary of changes:

- Moved into the Canvas extension:
- Draw ordering logic (including `Kapi.setOrderFunction`, `Kapi.unsetOrderFunction` and `Kapi.moveActorToLayer`)
- Drawing related code (including private `draw` function, `Kapi.render`, `Kapi.redraw`)
- `beforeDraw` and `frameRender` events (the latter renamed to `afterDraw`)

- Renamed `Kapi.calculateActorPositions` to `Kapi.update`

- Renamed `Actor.calculatePosition` to `Actor.updateState`

- Fire new events in core: `beforeUpdate`, `afterUpdate`, `addActor` and `removeActor`

- Changed Actor constructor arguments to: `context`, `setup`, `update` and `teardown`

- CanvasActor has the same arguments, with the addition of `draw`, which replaces `render`

- The rendering code in the canvas extension is called when `afterUpdate` is fired.

- Added new unit test suites for events and canvas.

-------------

Here is a difference between what was discussed in #16 and what I ended up doing:

- I did not rename `Kapi.update` to `Kapi.updateActorStates` because I felt that it was too long a name for such an important method. However, I'm not comfortable with it not being consistent with `Actor.updateState` as you pointed out in a comment.

Some new things which had not been discussed:

- I renamed `_lastRenderedMillisecond` to `_lastUpdatedMillisecond` because it didn't really make sense anymore.

- `exportTimeline` is overloaded in the canvas extension.