Skip to content

Commit

Permalink
[Closes #8] Update to support Underscore 1.6.0
Browse files Browse the repository at this point in the history
- Using same version as Underscore so it's easy to know what version
you're going against (will use revision for UKO-specific fixes)
- Fixed nuspec KO version
- Updated Grunt
- Added tests for new functions
  • Loading branch information
kamranayub committed Jun 7, 2014
1 parent 3223717 commit 91cde1b
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 90 deletions.
60 changes: 60 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*global module:false*/
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

jslint: {
client: {
src: [
'src/**/*.js'
]
}
},

concat: {
options: {
stripBanners: true,
banner: '// <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "// " + pkg.homepage + "\\n" : "" %>' +
'// Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n'
},
dist: {
src: ['src/underscore-ko.js'],
dest: 'build/<%= pkg.name %>-<%= pkg.version %>.js',
nonull: true
}
},

min: {
dist: {
src: ['build/<%= pkg.name %>-<%= pkg.version %>.js'],
dest: 'build/<%= pkg.name %>-<%= pkg.version %>.min.js'
}
},

clean: ['build/*.js', 'build/*.nupkg'],

shell: {
nuget: {
command: 'tools\\nuget pack UnderscoreKO.nuspec -Version <%= pkg.version %> -Output build',
stdout: true
}
}
});

// Exec task
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-jslint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-min');
grunt.loadNpmTasks('grunt-jasmine-node');

// Default task.
grunt.registerTask('default', ['clean', 'concat', 'min', 'shell']);

};
6 changes: 3 additions & 3 deletions UnderscoreKO.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<projectUrl>https://github.com/kamranayub/UnderscoreKO</projectUrl>
<licenseUrl>http://www.opensource.org/licenses/mit-license.php</licenseUrl>
<tags>knockoutjs knockout underscore underscorejs javascript js</tags>
<releaseNotes>Updated to support _.where in Underscore 1.4.3</releaseNotes>
<releaseNotes>See GitHub releases for changelog</releaseNotes>
<dependencies>
<dependency id="knockoutjs" version="1.2" />
<dependency id="underscore.js" version="1.2" />
<dependency id="knockoutjs" version="2.2" />
<dependency id="underscore.js" version="1.6.0" />
</dependencies>
</metadata>
<files>
Expand Down
4 changes: 0 additions & 4 deletions build/underscore-ko-1.2.2.min.js

This file was deleted.

29 changes: 20 additions & 9 deletions build/underscore-ko-1.2.2.js → build/underscore-ko-1.6.0.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/*! underscore-ko - v1.2.2 - 2013-01-15
* https://github.com/kamranayub/UnderscoreKO
* Copyright (c) 2013 ; Licensed MIT */

(function (ko, _, undefined) {
// underscore-ko - v1.6.0 - 2014-06-07
// https://github.com/kamranayub/UnderscoreKO
// Copyright (c) 2014 Kamran Ayub (http://kamranicus.com); Licensed MIT */
(function (factory) {
if (typeof define === 'function' && define['amd']) {
// AMD Anonymous module
define(['knockout', 'underscore'], factory);
} else {
factory(window['ko'], window['_']);
}
}(function (ko, _, undefined) {

/* _ methods that take the list as the first arg (and their aliases) */
var methods = [
Expand All @@ -14,6 +20,7 @@
"find", "detect",
"filter", "select", "filter_", "select_",
"where",
"findWhere",
"reject", "reject_",
"all", "every",
"any", "some",
Expand All @@ -24,24 +31,27 @@
"min",
"sortBy", "sortBy_",
"groupBy", "groupBy_",
"indexBy",
"countBy",
"sortedIndex",
"shuffle", "shuffle_",
"sample",
"size",

// Arrays
"first", "head","take",
"first", "head", "take",
"initial",
"last",
"rest", "tail", "rest_", "tail_","drop","drop_",
"rest", "tail", "drop", "rest_", "tail_", "drop_",
"compact", "compact_",
"flatten", "flatten_",
"without", "without_",
"partition",
"union","union_",
"intersection",
"difference",
"uniq", "unique", "uniq_", "unique_",
"zip","zip_",
"zip", "zip_",
"object",
"indexOf",
"lastIndexOf",
Expand Down Expand Up @@ -91,4 +101,5 @@
}
});

})(ko, _);
})
);
1 change: 1 addition & 0 deletions build/underscore-ko-1.6.0.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 0 additions & 63 deletions grunt.js

This file was deleted.

14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "underscore-ko",
"description": "Attaches Underscore.js array and collection functions (and mutators) to Knockout.js observable arrays.",
"version": "1.2.2",
"version": "1.6.0",
"author": "Kamran Ayub (http://kamranicus.com)",
"homepage": "https://github.com/kamranayub/UnderscoreKO",
"repository": {
Expand All @@ -18,11 +18,17 @@
}
],
"dependencies": {
"underscore": "~1.4.3",
"underscore": "~1.6.0",
"knockout-client": "~2.2.0"
},
"devDependencies": {
"grunt": "~0.3.17",
"grunt-shell": "~0.1.4"
"grunt": "~0.4.5",
"grunt-shell": "~0.7.0",
"grunt-jslint": "~1.1.12",
"grunt-concat": "~0.1.6",
"grunt-min": "~0.1.0",
"grunt-jasmine-node": "~0.2.1",
"grunt-contrib-concat": "~0.4.0",
"grunt-contrib-clean": "~0.5.0"
}
}
11 changes: 8 additions & 3 deletions spec/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ describe("UnderscoreKO", function () {
"max",
"min",
"sortBy",
"groupBy"
"indexBy",
"countBy",
"groupBy",
"partition"
],
reductionFns = [
"each", "forEach",
Expand All @@ -33,6 +36,7 @@ describe("UnderscoreKO", function () {
],
singleArgFns = [
"include", "contains",
"sample",
"sortedIndex",
"lastIndexOf"
],
Expand All @@ -43,6 +47,7 @@ describe("UnderscoreKO", function () {
],
miscFns = [
"where",
"findWhere",
"invoke",
"pluck",
"shuffle",
Expand All @@ -67,15 +72,15 @@ describe("UnderscoreKO", function () {
"zip_"
];

it("supports all 46 underscore methods", function () {
it("supports all 51 underscore methods", function () {
var count = 0;

_.union(predicateFns, reductionFns, noArgFns, singleArgFns, arrayArgFns, miscFns).forEach(function (fn) {
count++;
expect(vm.arr[fn]).toBeDefined();
});

expect(count).toEqual(46);
expect(count).toEqual(51);
});

it("supports 18 mutator methods", function () {
Expand Down
10 changes: 7 additions & 3 deletions src/underscore-ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"find", "detect",
"filter", "select", "filter_", "select_",
"where",
"findWhere",
"reject", "reject_",
"all", "every",
"any", "some",
Expand All @@ -27,24 +28,27 @@
"min",
"sortBy", "sortBy_",
"groupBy", "groupBy_",
"indexBy",
"countBy",
"sortedIndex",
"shuffle", "shuffle_",
"sample",
"size",

// Arrays
"first", "head","take",
"first", "head", "take",
"initial",
"last",
"rest", "tail", "rest_", "tail_","drop","drop_",
"rest", "tail", "drop", "rest_", "tail_", "drop_",
"compact", "compact_",
"flatten", "flatten_",
"without", "without_",
"partition",
"union","union_",
"intersection",
"difference",
"uniq", "unique", "uniq_", "unique_",
"zip","zip_",
"zip", "zip_",
"object",
"indexOf",
"lastIndexOf",
Expand Down
Loading

0 comments on commit 91cde1b

Please sign in to comment.