Skip to content

Commit

Permalink
adding attribute tag
Browse files Browse the repository at this point in the history
  • Loading branch information
eavichay committed Oct 10, 2017
1 parent 6268442 commit efff10e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Decorators.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export declare function tag(selector:string):any;
export declare function template(tpl:string):any;
export declare function useShadow(value:boolean):any;
export declare function useShadow(value:boolean):any;
export declare function attribute():any;
16 changes: 7 additions & 9 deletions Decorators.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Slim} from "./Slim"

module.exports = {
tag: function(selector) {
return function(target) {
Expand All @@ -17,14 +19,10 @@ module.exports = {
return function(target) {
target.prototype.__defineGetter__('useShadow', function() { return value; })
}
}
},

// bindable: function() {
// const args = Array.prototype.slice.call(arguments)
// return function(target) {
// target.prototype._isPropertyBindable = function (prop) {
// return args.indexOf(prop) >= 0
// }
// }
// }
attribute: function(target, key) {
target.constructor.observedAttributes = target.constructor.observedAttributes || []
target.constructor.observedAttributes.push(Slim.__camelToDash(key))
}
};
11 changes: 9 additions & 2 deletions Slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ var Slim = function (_CustomElement2) {
if (Slim.__prototypeDict[tag] === clazz) return tag;
}
}
}, {
key: 'getClass',
value: function getClass(tag) {
return Slim.__prototypeDict[tag];
}
}, {
key: '__createUqIndex',
value: function __createUqIndex() {
Expand Down Expand Up @@ -662,10 +667,12 @@ var Slim = function (_CustomElement2) {
}, {
key: 'attributeChangedCallback',
value: function attributeChangedCallback(attr, oldValue, newValue) {
var camelCased = Slim.__dashToCamel(attr);
if (oldValue === newValue) return;
if (!this._bindings) return;
if (this._bindings[attr]) {
this[Slim.__dashToCamel(attr)] = newValue;
if (this._bindings[camelCased] || this._bindables && this._bindables.hasOwnProperty(camelCased)) {
this[camelCased] = newValue;
this._executeBindings(camelCased);
}
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion Slim.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/Slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class Slim extends HTMLElement {
}
}

static getClass(tag) {
return Slim.__prototypeDict[tag]
}

static __createUqIndex() {
Slim.__uqIndex++;
return Slim.__uqIndex.toString(16);
Expand Down Expand Up @@ -719,10 +723,12 @@ class Slim extends HTMLElement {
}

attributeChangedCallback(attr, oldValue, newValue) {
const camelCased = Slim.__dashToCamel(attr)
if (oldValue === newValue) return;
if (!this._bindings) return;
if (this._bindings[attr]) {
this[Slim.__dashToCamel(attr)] = newValue;
if (this._bindings[camelCased] || (this._bindables && this._bindables.hasOwnProperty(camelCased))) {
this[camelCased] = newValue;
this._executeBindings(camelCased)
}
}

Expand Down

0 comments on commit efff10e

Please sign in to comment.