Skip to content

Commit

Permalink
validate and fail if the event is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
glena authored and hzalaz committed Jan 2, 2017
1 parent 43fd233 commit f3ff005
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/core.js
Expand Up @@ -33,14 +33,29 @@ export default class Base extends EventEmitter {

super();

this.validEvents = [
'show',
'hide',
'unrecoverable_error',
'authenticated',
'authorization_error',
'hash_parsed'
];

this.id = idu.incremental();
this.engine = engine;
const hookRunner = ::this.runHook;
const emitEventFn = this.emit.bind(this);

go(this.id);

setupLock(this.id, clientID, domain, options, hookRunner, emitEventFn);
let m = setupLock(this.id, clientID, domain, options, hookRunner, emitEventFn);

this.on('newListener', (type) => {
if (this.validEvents.indexOf(type) === -1) {
l.emitUnrecoverableErrorEvent(m, `Invalid event "${type}".`)
}
});

if (!Base.hasScheduledAuthCallback) {
Base.hasScheduledAuthCallback = true;
Expand Down
2 changes: 2 additions & 0 deletions src/core/actions.js
Expand Up @@ -22,6 +22,8 @@ export function setupLock(id, clientID, domain, options, hookRunner, emitEventFn
m = l.runHook(m, "didInitialize", options);

swap(setEntity, "lock", id, m);

return m;
}

export function handleAuthCallback() {
Expand Down

0 comments on commit f3ff005

Please sign in to comment.