Skip to content

Commit

Permalink
release 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
falkolab committed Mar 14, 2016
1 parent b7b3f46 commit 9ecf546
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ Example #1:
require('com.falkolab.lvmc').transformEvent(evt);
alert('`itemclick` event:\n'+ JSON.stringify(_.omit(evt, 'source', 'section'), null, '\t'));
});

Example #2:

list.addEventListener('itemclick', function(evt) {
var lvmc = require('com.falkolab.lvmc');
lvmc.transformEvent(evt);
var section = lvmc.wrap(evt.section);
var dataItem = section.getItemAt(evt.itemIndex);
require('com.falkolab.lvmc').transformEvent(evt);
// no need to wrap section if you use `transformEvent`
var dataItem = evt.section.getItemAt(evt.itemIndex);
...
section.updateItemAt(evt.itemIndex, dataItem);
evt.section.updateItemAt(evt.itemIndex, dataItem);
}

## Methods
Expand Down
27 changes: 16 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,25 @@ exports.DIVIDER = '@';

exports.wrap = function(obj) {
var methods;
if(obj.apiName == 'Ti.UI.ListSection') {
if(obj.apiName == 'Ti.UI.ListSection' && !_.isUndefined(obj.columns)) {
methods = ['setItems', 'getItems', 'getItemAt', 'appendItems', 'insertItemsAt', 'replaceItemsAt', 'deleteItemsAt', 'updateItemAt'];
} else if(obj.apiName == 'Ti.UI.ListView') {
} else if(obj.apiName == 'Ti.UI.ListView' && !_.isUndefined(obj.columns)) {
methods = ['appendSection', 'setMarker', 'addMarker'];
} else {
return obj;
}

var self = this;
if(methods) {
return _.extend({obj: obj}, _.chain(methods).map(function(methodName) {
return [methodName, function() {
return self[methodName].apply(self, [this.obj].concat(Array.prototype.slice.call(arguments)));
}];
}).object().value());
}
var wrapped = _.extend({obj: obj}, _.chain(methods).map(function(methodName) {
return [methodName, function() {
return self[methodName].apply(self, [this.obj].concat(Array.prototype.slice.call(arguments)));
}];
}).object().value());

wrapped.columns = obj.columns;
wrapped.defaultItemTemplate = obj.columns;

return wrapped;
};

// ***********************
Expand Down Expand Up @@ -112,8 +118,6 @@ exports.transformEvent = function(evt, columns /* optional */) {
}

if(evt.section) {
var section = evt.section;

columns = columns || evt.section.columns;
if(columns) {
if(evt.bindId) {
Expand All @@ -125,6 +129,7 @@ exports.transformEvent = function(evt, columns /* optional */) {
}
}
}
evt.section = this.wrap(evt.section);
}
}

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": "com.falkolab.lvmc",
"version": "1.0.1",
"version": "1.0.2",
"description": "Multicolumn ListView helper library",
"main": "./index.js",
"titaniumManifest": {
Expand Down

0 comments on commit 9ecf546

Please sign in to comment.