Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-10347] Implemented support for applyProperties method. #2699

Merged
merged 3 commits into from
Aug 10, 2012
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions apidoc/Titanium/Proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ methods:
summary: A dictionary of keys and values to add to the <Titanium.Event> object
sent to the listeners.
type: Dictionary
- name: applyProperties
summary: Applies the properties to the proxy.
description: |
Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that
myproxy[key] = value.
parameters:
- name: props
summary: A dictionary of properties to apply.
type: Dictionary
since: "2.2.0"
7 changes: 7 additions & 0 deletions mobileweb/titanium/Ti/_/Evented.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ define(function() {
}
},

applyProperties: function(props) {
var i;
for(i in props) {
this[i] = props[i];
}
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you could have just done:

applyProperties: function(props) {
    require.mix(this, props);
}

There's a bit of a debate if var i should go in the for loop or not. JSLint says var i should NOT go in the for loop. However, JSLint says you should do a hasOwnProperty() check on i. mix() does the hasOwnProperty() check. I would say move the var into the for loop or use require.mix().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

_addEventModifier: function(name, handler) {
this._modifiers || (this._modifiers = {});
(require.is(name, "Array") ? name : [name]).forEach(function(n) {
Expand Down