Skip to content

Commit

Permalink
feat(ServerSideRendering): opt-in event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Jun 15, 2016
1 parent 6c26a10 commit 6d05f3a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var renderer = new Marklib.Rendering(document, {
Marklib triggers events that can be listened to with `instance.on('event-name')`. Events are build with
`wolfy87-eventemitter` (https://github.com/Olical/EventEmitter). The following Events are available:

Before you can actually receive events, you need to register the event handler with `registerEvents`

| Event-Name | Description | Arguments |
| ------------- |-------------|-------------|
| `click` | triggered when clicked on a marking. | `(originalEvent, instanceHierarchy)`
Expand Down
13 changes: 3 additions & 10 deletions src/main/RenderingEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ export default class RenderingEvents extends EventEmitter {

return null;
}

static globalEmitter() {
return RenderingEvents.staticEventListener;
}
}

RenderingEvents.globalEmitter = () => RenderingEvents.staticEventListener;

RenderingEvents.staticEventListener = new EventEmitter();

const init = () => {
export const registerEvents = () => {
const currentHoverInstances = new Set();
const betweenInstances = new Set();

Expand Down Expand Up @@ -219,8 +217,3 @@ const init = () => {
}
}, true);
};

if (!global.__MARKLIB_EVENTS__) {
global.__MARKLIB_EVENTS__ = true;
init();
}
4 changes: 2 additions & 2 deletions src/main/modules/Marklib.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Rendering from '../Rendering';
import Util from '../util/Util';
import RenderResult from '../RenderResult';
import RenderingEvents from '../RenderingEvents';
import RenderingEvents, { registerEvents } from '../RenderingEvents';

export { Rendering, Util, RenderResult, RenderingEvents };
export { Rendering, Util, RenderResult, RenderingEvents, registerEvents };
3 changes: 2 additions & 1 deletion src/test/RenderingEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import setup from 'setup';
import Rendering from 'Rendering';
import RenderResult from 'RenderResult';
import { EVENT_CLICK, EVENT_MOUSEENTER, EVENT_MOUSELEAVE } from 'RenderingEvents';
import { EVENT_CLICK, EVENT_MOUSEENTER, EVENT_MOUSELEAVE, registerEvents } from 'RenderingEvents';
setup();
registerEvents();

/**
* @return {Rendering}
Expand Down

0 comments on commit 6d05f3a

Please sign in to comment.