Skip to content

Commit

Permalink
fix: emit event for plugin register
Browse files Browse the repository at this point in the history
  • Loading branch information
venkatperi committed Aug 17, 2017
1 parent aa733b8 commit 977f30a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 16 additions & 1 deletion lib/js_dsl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable class-methods-use-this */
// Copyright 2017, Venkat Peri.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand Down Expand Up @@ -28,14 +29,21 @@ const debug = require( 'debug' )( 'js_dsl' );
* JavaScript DSLs.
*/
class JsDsl extends EventEmitter {
constructor( parentBuilder ) {
constructor( name, parentBuilder ) {
super();
if ( typeof name !== 'string' ) {
// eslint-disable-next-line no-param-reassign
[name, parentBuilder] = [null, name];
}
this._name = name;
this._parentBuilder = parentBuilder;
this.__contextStack = [];
this._globalsStack = {};
this._factories = {};
this._propertyNames = [];
this._methodNames = [];
this.on( 'register', this.register.bind( this ) );
this.emit( 'register', this );
}

get _child() {
Expand All @@ -61,6 +69,10 @@ class JsDsl extends EventEmitter {
return this._context._parent;
}

get name() {
return this._name;
}

get propertyNames() {
return this._propertyNames;
}
Expand Down Expand Up @@ -292,6 +304,9 @@ class JsDsl extends EventEmitter {
}
}

register() {
}

/**
* Register a factory for a node name
*
Expand Down
3 changes: 1 addition & 2 deletions test/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class TipFactory extends AbstractFactory {
}

class TreeBuilder extends JsDsl {
constructor() {
super();
register() {
this.registerFactory( 'tree', new TreeFactory() );
this.registerFactory( 'tip', new TipFactory() );
this.registerPropertyNames( ['name', 'description'] );
Expand Down

0 comments on commit 977f30a

Please sign in to comment.