Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
fix event delegation and setting default element
Browse files Browse the repository at this point in the history
  • Loading branch information
avetisk committed Feb 25, 2014
1 parent 6ea43fc commit 5ecd12a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ var dom = document.createElement('div');
* @return {View}
*/
var View = module.exports = function (options) {
EventEmitter.call(this);

this.options = defaults(options || {}, View.defaultOptions);
this._bindings = [];
this._el = this.options.el;

EventEmitter.call(this);
this.options.el && (this.el = this.options.el);
};

var prototype = View.prototype = Object.create(EventEmitter.prototype);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ak-view",
"version": "0.0.5",
"version": "0.0.6",
"description": "client side view",
"keywords": [
"view"
Expand Down
8 changes: 6 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ describe('View', function () {
});

it('view#el = dom, view#el = dom2', function (done) {
var el = createElement('bolo');
var dom = createElement('hari');
var dom2 = createElement('haribol');
var parents = [dom, dom2];
var parents = [el, dom, dom2];
var counterElement = 0;
var counterDelegate = 0;
var counterUndelegate = 0;

var view = new View({
'el': el,
'domEvents': {
'span': {
'click': function (e) {
assert.equal(e.target.parentElement, parents.shift());

if (! parents.length && counterElement === 2 && counterDelegate === 2 && counterUndelegate === 1) {
if (! parents.length && counterElement === 2 && counterDelegate === 2 && counterUndelegate === 2) {
done();
}
}
Expand All @@ -102,6 +104,8 @@ describe('View', function () {
view.el = '';
}, '`el` must be a HTMLElement.');

view.el.querySelector('span').click();

view.el = dom;
view.el.querySelector('span').click();

Expand Down

0 comments on commit 5ecd12a

Please sign in to comment.