Skip to content

Commit

Permalink
CHG: rename property to attribute in component/module
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Dec 27, 2016
1 parent 0542e76 commit 37fed7b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 49 deletions.
38 changes: 20 additions & 18 deletions dist/tao.js
Original file line number Diff line number Diff line change
Expand Up @@ -27746,21 +27746,21 @@ return jQuery;
return this;
};

TaoModule.get = function(propertyName, getMethod) {
return Object.defineProperty(this.prototype, propertyName, {
TaoModule.get = function(attributeName, getMethod) {
return Object.defineProperty(this.prototype, attributeName, {
get: getMethod,
configurable: true
});
};

TaoModule.set = function(propertyName, setMethod) {
return Object.defineProperty(this.prototype, propertyName, {
TaoModule.set = function(attributeName, setMethod) {
return Object.defineProperty(this.prototype, attributeName, {
set: setMethod,
configurable: true
});
};

TaoModule.property = function() {
TaoModule.attribute = function() {
var i, names, options;
names = 2 <= arguments.length ? slice.call(arguments, 0, i = arguments.length - 1) : (i = 0, []), options = arguments[i++];
if (options == null) {
Expand All @@ -27774,14 +27774,14 @@ return jQuery;
return function(name) {
_this.get(name, function() {
var ref;
return (ref = this._properties[name]) != null ? ref : options["default"];
return (ref = this._attributes[name]) != null ? ref : options["default"];
});
return _this.set(name, function(val) {
var name1;
if (this._properties[name] === val) {
if (this._attributes[name] === val) {
return;
}
this._properties[name] = val;
this._attributes[name] = val;
return typeof this[name1 = "_" + name + "Changed"] === "function" ? this[name1]() : void 0;
});
};
Expand All @@ -27793,7 +27793,7 @@ return jQuery;
if (options == null) {
options = {};
}
this._properties = {};
this._attributes = {};
if (typeof options === 'object') {
for (key in options) {
val = options[key];
Expand Down Expand Up @@ -27874,7 +27874,9 @@ return jQuery;
};

TaoApplication.prototype._initI18n = function() {
return typeof I18n !== "undefined" && I18n !== null ? I18n.locale = this.locale : void 0;
if (I18n && this.locale) {
return I18n.locale = this.locale;
}
};

TaoApplication.prototype._initIcons = function($page) {
Expand Down Expand Up @@ -27930,12 +27932,12 @@ return jQuery;
};
})(this)).on('turbolinks:render', (function(_this) {
return function(e) {
return _this.trigger('page-render', [$('body > .page')]);
return _this.trigger('page-render', [$('body > .tao-page')]);
};
})(this)).on('turbolinks:load', (function(_this) {
return function(e) {
var $page;
$page = $('body > .page');
$page = $('body > .tao-page');
if (!($page.length > 0)) {
return;
}
Expand Down Expand Up @@ -30930,21 +30932,21 @@ var Deferred = void 0;
return this;
};

_Class.get = function(propertyName, getMethod) {
return Object.defineProperty(this.prototype, propertyName, {
_Class.get = function(attributeName, getMethod) {
return Object.defineProperty(this.prototype, attributeName, {
get: getMethod,
configurable: true
});
};

_Class.set = function(propertyName, setMethod) {
return Object.defineProperty(this.prototype, propertyName, {
_Class.set = function(attributeName, setMethod) {
return Object.defineProperty(this.prototype, attributeName, {
set: setMethod,
configurable: true
});
};

_Class.property = function() {
_Class.attribute = function() {
var i, names, options;
names = 2 <= arguments.length ? slice.call(arguments, 0, i = arguments.length - 1) : (i = 0, []), options = arguments[i++];
if (options == null) {
Expand Down Expand Up @@ -31080,7 +31082,7 @@ var Deferred = void 0;
return TaoPage.__super__.constructor.apply(this, arguments);
}

TaoPage.property('layout');
TaoPage.attribute('layout');

TaoPage.prototype.prepareCache = function() {
return $(this).find('.tao-component').each((function(_this) {
Expand Down
6 changes: 3 additions & 3 deletions lib/assets/javascripts/tao/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TaoApplication extends TaoModule
$(@).removeClass 'disabled'

_initI18n: ->
I18n?.locale = @locale
I18n.locale = @locale if I18n && @locale

_initIcons: ($page) ->
$icons = $page.siblings('#tao-icons')
Expand Down Expand Up @@ -57,10 +57,10 @@ class TaoApplication extends TaoModule
@trigger 'before-page-render', [$ e.originalEvent?.data.newBody]

.on 'turbolinks:render', (e) =>
@trigger 'page-render', [$('body > .page')]
@trigger 'page-render', [$('body > .tao-page')]

.on 'turbolinks:load', (e) =>
$page = $ 'body > .page'
$page = $ 'body > .tao-page'
return unless $page.length > 0
@_initIcons $page
@_initPage $page
Expand Down
10 changes: 5 additions & 5 deletions lib/assets/javascripts/tao/component.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ TaoComponentBasedOn = (superClass = 'HTMLElement') ->
obj.included?.call(@)
@

@get: (propertyName, getMethod) ->
Object.defineProperty @prototype, propertyName,
@get: (attributeName, getMethod) ->
Object.defineProperty @prototype, attributeName,
get: getMethod
configurable: true

@set: (propertyName, setMethod) ->
Object.defineProperty @prototype, propertyName,
@set: (attributeName, setMethod) ->
Object.defineProperty @prototype, attributeName,
set: setMethod
configurable: true

@property: (names..., options = {}) ->
@attribute: (names..., options = {}) ->
unless typeof options == 'object'
names.push(options)
options = {}
Expand Down
20 changes: 10 additions & 10 deletions lib/assets/javascripts/tao/module.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ class TaoModule
obj.included?.call(@)
@

@get: (propertyName, getMethod) ->
Object.defineProperty @prototype, propertyName,
@get: (attributeName, getMethod) ->
Object.defineProperty @prototype, attributeName,
get: getMethod
configurable: true

@set: (propertyName, setMethod) ->
Object.defineProperty @prototype, propertyName,
@set: (attributeName, setMethod) ->
Object.defineProperty @prototype, attributeName,
set: setMethod
configurable: true

@property: (names..., options = {}) ->
@attribute: (names..., options = {}) ->
unless typeof options == 'object'
names.push(options)
options = {}

names.forEach (name) =>
@get name, ->
@_properties[name] ? options.default
@_attributes[name] ? options.default
@set name, (val) ->
return if @_properties[name] == val
@_properties[name] = val
return if @_attributes[name] == val
@_attributes[name] = val
@["_#{name}Changed"]?()

constructor: (options = {}) ->
@_properties = {}
@_attributes = {}

if typeof options == 'object'
@[key] = val for key, val of options

Expand Down
2 changes: 1 addition & 1 deletion lib/assets/javascripts/tao/page.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class TaoPage extends TaoComponent

@property 'layout'
@attribute 'layout'

prepareCache: ->
$(@).find('.tao-component').each (i, el) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/tao_on_rails/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module TaoOnRails
module Rails
VERSION = "0.4.4"
VERSION = "0.5.0"
end
end
10 changes: 5 additions & 5 deletions test/javascripts/component_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module 'TaoComponent',

@tag: 'test-component'

@property 'name', 'age', observe: true
@attribute 'name', 'age', observe: true

@property 'active', default: true
@attribute 'active', default: true

_init: ->
@trigger 'initialized'
Expand All @@ -36,7 +36,7 @@ module 'TaoComponent',
test 'inherits from HTMLElement', (assert) ->
assert.ok @TestComponent.prototype instanceof HTMLElement

test 'has observed properties', (assert) ->
test 'has observed attributes', (assert) ->
nameChangedCount = 0
@component.on 'nameChanged', ->
nameChangedCount++
Expand All @@ -50,7 +50,7 @@ module 'TaoComponent',
assert.equal @component.getAttribute('name'), 'farthinker'
assert.equal nameChangedCount, 1

test 'has properties with default value', (assert) ->
test 'has attributes with default value', (assert) ->
assert.equal @component.active, true
assert.equal @component.hasAttribute('active'), false

Expand Down Expand Up @@ -99,6 +99,6 @@ module 'TaoComponent',
assert.equal disconnectCount, 1
done()

test 'jq property returns jquery object', (assert) ->
test 'jq attribute returns jquery object', (assert) ->
assert.ok @component.jq.jquery
assert.equal @component.jq.get(0), @component
12 changes: 6 additions & 6 deletions test/javascripts/module_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ module 'TaoModule',

before: ->
class @ParentModule extends TaoModule
@property 'x', default: 1
@property 'y', default: 2
@attribute 'x', default: 1
@attribute 'y', default: 2

_xChanged: ->
@trigger 'xChanged'


class @ChildModule extends @ParentModule
@property 'x', default: 3
@property 'z', default: 0
@attribute 'x', default: 3
@attribute 'z', default: 0

, ->

Expand All @@ -26,7 +26,7 @@ module 'TaoModule',
assert.equal parentInstance.x, 3
assert.equal childInstance.x, 4

test 'property inheritance', (assert) ->
test 'attribute inheritance', (assert) ->
parentInstance = new @ParentModule()
childInstance = new @ChildModule()

Expand All @@ -36,7 +36,7 @@ module 'TaoModule',
assert.equal childInstance.y, 2
assert.equal childInstance.z, 0

test 'property changed hook', (assert) ->
test 'attribute changed hook', (assert) ->
parentInstance = new @ParentModule()

xChangedCount = 0
Expand Down

0 comments on commit 37fed7b

Please sign in to comment.