Skip to content

Commit

Permalink
Removed extended babel plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
malomalo committed Aug 12, 2020
1 parent 0d445d8 commit 7941a45
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
1 change: 0 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
["@babel/preset-env", { "targets": { "node": "current" } } ]
],
"plugins": [
"babel-plugin-transform-class-extended-hook",
"@babel/plugin-proposal-class-properties"
]
}
11 changes: 7 additions & 4 deletions lib/viking/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import View from 'viking/view';
import Router from 'config/routes';
import initializers from 'config/initializers/*';
import {result} from 'viking/support';
import {replace} from 'viking/support/dom';

Expand All @@ -25,8 +23,13 @@ export default class Application extends View {
}

setup() {
this.router = new Router(this);
initializers.forEach((i) => i(this));
if (this.constructor.router) {
this.router = new this.constructor.router(this);
}

if (this.constructor.initializers) {
this.constructor.initializers.forEach((i) => i(this));
}
}

async display(view, options) {
Expand Down
26 changes: 21 additions & 5 deletions lib/viking/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,28 @@ export default class View extends EventBus {
'record'
];

static extended(child) {
if (child.events) {
each(this.events, (k, v) => {
if (child.events[k] === undefined) { child.events[k] = v; }
});

static getEvents() {
if (this.hasOwnProperty('_events')) {
return this._events;
}

if (!this.hasOwnProperty('events')) {
if (Object.getPrototypeOf(this).getEvents) {
this._events = Object.getPrototypeOf(this).getEvents();
} else {
this._events = {};
}
return this._events;
}

if (Object.getPrototypeOf(this).getEvents) {
this._events = Object.assign({}, Object.getPrototypeOf(this).getEvents(), this.events);
} else {
this._events = this.events;
}

return this._events;
}

// An array for storing subView attached to this view
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "viking",
"version": "2.0.0.rc1",
"author": "Jonathan Bracy <[email protected]>",
"description": "Viking.js is an open-source web framework for JavaScript. Inspired by Backbone.js & Ruby on Rails; it makes it easier to write client side JavaScript applications.",
"url": "http://vikingjs.com",
Expand Down Expand Up @@ -32,7 +33,6 @@
"test": "npx mocha -r @babel/register -r test/testSetup.js test/testHelper.js 'test/**/*.js'",
"esdoc": "npx esdoc"
},
"version": "1.0.0",
"dependencies": {
"babel-plugin-transform-class-extended-hook": "^1.0.3",
"babel-plugin-transform-class-inherited-hook": "^3.2.0",
Expand Down
4 changes: 2 additions & 2 deletions test/viewTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ describe('Viking.View', () => {
};
}

assert.deepEqual((new MySubView()).events, {
assert.deepEqual(MySubView.getEvents(), {
click: 'click',
hover: 'hover'
});
Expand All @@ -543,7 +543,7 @@ describe('Viking.View', () => {
};
}

assert.deepEqual((new SubView()).events, {
assert.deepEqual(SubView.getEvents(), {
click: 'click',
hover: 'newHover'
});
Expand Down

0 comments on commit 7941a45

Please sign in to comment.