Skip to content

Commit 771cefb

Browse files
author
Narendra Sisodiya
committed
releasing v1.0.1 - pitana.js - add support for adding a new accessorType
1 parent ff02b34 commit 771cefb

File tree

7 files changed

+129
-110
lines changed

7 files changed

+129
-110
lines changed

CHANGE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
1.0.1
3+
=====
4+
* Support for adding a new accessorType (pitana.accessorType)
5+
6+
1.0.0
7+
=====
8+
* Initial Release,
9+
* Support accessor, methods, registerElement
10+
* Support for custom Event bus

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = function(grunt) {
1313
"src/pitana.domEvents.js",
1414
"src/pitana.HTMLElement.js",
1515
"src/pitana.ObjectMap.js",
16+
"src/pitana.accessorType.js",
1617
"src/pitana.registerElement.js"
1718
];
1819
grunt.initConfig({

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pitana.js",
33
"repo": "pitana/pitana.js",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"main": "dist/pitana.js",
66
"keywords": [
77
"scalable",

dist/pitana.js

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,56 @@
382382
});
383383

384384
})();
385+
;/**
386+
* Created by narendra on 13/4/15.
387+
*/
388+
389+
(function() {
390+
"use strict";
391+
392+
var boolStringToBoolean = {
393+
"true": true,
394+
"false": false,
395+
null: false,
396+
"": true
397+
};
398+
pitana.accessorType = {};
399+
pitana.accessorType.int = {
400+
get: function(attrName, attrObj) {
401+
var val = this.getAttribute(attrName);
402+
if (val !== null) {
403+
return parseInt(val, 10);
404+
} else {
405+
return attrObj.default;
406+
}
407+
},
408+
set: function(attrName, newVal, attrObj) {
409+
if (typeof newVal === "number" && this[attrName] !== newVal + "") {
410+
this.setAttribute(attrName, newVal);
411+
}
412+
}
413+
};
414+
415+
pitana.accessorType.boolean = {
416+
get: function(attrName) {
417+
var val = boolStringToBoolean[this.getAttribute(attrName)];
418+
if (val === undefined) {
419+
return false;
420+
} else {
421+
return val;
422+
}
423+
},
424+
set: function(attrName, newVal, attrObj) {
425+
if (this[attrName] !== newVal && typeof newVal === "boolean") {
426+
if (newVal === true) {
427+
this.setAttribute(attrName, "");
428+
} else {
429+
this.removeAttribute(attrName);
430+
}
431+
}
432+
}
433+
};
434+
})();
385435
;/**
386436
* Created by narendra on 15/3/15.
387437
*/
@@ -437,68 +487,22 @@
437487
view.attributeChangedCallback.apply(view, arguments);
438488
};
439489

440-
ElementPrototype.getIntegerAttribute = function(attrName, attrObj) {
441-
var val = this.getAttribute(attrName);
442-
if (val !== null) {
443-
return parseInt(val, 10);
444-
} else {
445-
return attrObj.default;
446-
}
447-
};
448-
ElementPrototype.setIntegerAttribute = function(attrName, newVal, attrObj) {
449-
if (typeof newVal === "number" && this[attrName] !== newVal + "") {
450-
this.setAttribute(attrName, newVal);
451-
}
452-
};
453-
ElementPrototype.getBooleanAttribute = function(attr) {
454-
var boolStringToBoolean = {
455-
"true": true,
456-
"false": false,
457-
null: false,
458-
"": true
459-
};
460-
var val = boolStringToBoolean[this.getAttribute(attr)];
461-
if (val === undefined) {
462-
return false;
463-
} else {
464-
return val;
465-
}
466-
};
467-
ElementPrototype.setBooleanAttribute = function(attr, newVal) {
468-
if (this[attr] !== newVal && typeof newVal === "boolean") {
469-
if (newVal === true) {
470-
this.setAttribute(attr, "");
471-
} else {
472-
this.removeAttribute(attr);
473-
}
474-
}
475-
};
476-
477490
if (ViewConstructor.prototype.accessors !== undefined) {
478491
pitana.util.for(ViewConstructor.prototype.accessors, function(attrObj, attrName) {
479492
var Prop = {};
480493
Prop[attrName] = {
481494
get: function() {
482-
switch (attrObj.type) {
483-
case "int":
484-
return this.getIntegerAttribute(attrName, attrObj);
485-
case "boolean":
486-
return this.getBooleanAttribute(attrName, attrObj);
487-
default:
488-
return this.getAttribute(attrName);
495+
if (pitana.accessorType[attrObj.type] !== undefined) {
496+
return pitana.accessorType[attrObj.type].get.call(this, attrName, attrObj);
497+
} else {
498+
return this.getAttribute(attrName);
489499
}
490500
},
491501
set: function(newVal) {
492-
switch (attrObj.type) {
493-
case "int":
494-
this.setIntegerAttribute(attrName, newVal, attrObj);
495-
break;
496-
case "boolean":
497-
this.setBooleanAttribute(attrName, newVal, attrObj);
498-
break;
499-
default:
500-
this.setAttribute(attrName, newVal);
501-
break;
502+
if (pitana.accessorType[attrObj.type] !== undefined) {
503+
pitana.accessorType[attrObj.type].set.call(this, attrName, newVal, attrObj);
504+
} else {
505+
this.setAttribute(attrName, newVal);
502506
}
503507
if (typeof attrObj.afterSet === "function") {
504508
attrObj.afterSet.apply(pitana.nodeToViewMapping.get(this), arguments);

0 commit comments

Comments
 (0)