Skip to content

Commit

Permalink
Merge pull request #51 from joelfillmore/master
Browse files Browse the repository at this point in the history
Fixes performance problems described in issue #45
  • Loading branch information
FotoVerite committed Mar 31, 2013
2 parents d1ca803 + a0d1eb5 commit b226b8d
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 533 deletions.
9 changes: 8 additions & 1 deletion BUILD/BUILD.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ for (var module in Faker) {
for (var method in Faker[module]) {
code += ( '\n' + 'Faker.' + module);
code += ( '.' + method + ' = ');
code += (Faker[module][method].toString() + ';\n');

// serialize arrays as JSON, otherwise use simple string conversion
var methodValue = Faker[module][method];
if (Array.isArray(methodValue)) {
code += JSON.stringify(methodValue) + ';\n';
} else {
code += (methodValue.toString() + ';\n');
}
}
}

Expand Down
213 changes: 46 additions & 167 deletions Faker.js

Large diffs are not rendered by default.

41 changes: 20 additions & 21 deletions MinFaker.js

Large diffs are not rendered by default.

213 changes: 46 additions & 167 deletions examples/js/Faker.js

Large diffs are not rendered by default.

258 changes: 107 additions & 151 deletions lib/definitions.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/lorem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var definitions = require('../lib/definitions');
var lorem = {
words: function (num) {
if (typeof num == 'undefined') { num = 3; }
return Helpers.shuffle(definitions.lorem()).slice(0, num);
return Helpers.shuffle(definitions.lorem).slice(0, num);
},

sentence: function (wordCount) {
Expand Down
2 changes: 1 addition & 1 deletion lib/phone_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var phone = {

// FIXME: this is strange passing in an array index.
phoneNumberFormat: function (phoneFormatsArrayIndex) {
return Helpers.replaceSymbolWithNumber(definitions.phone_formats()[phoneFormatsArrayIndex]);
return Helpers.replaceSymbolWithNumber(definitions.phone_formats[phoneFormatsArrayIndex]);
}
};

Expand Down
42 changes: 21 additions & 21 deletions lib/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,87 +13,87 @@ var random = {
},

city_prefix: function () {
return this.array_element(definitions.city_prefix());
return this.array_element(definitions.city_prefix);
},

city_suffix: function () {
return this.array_element(definitions.city_suffix());
return this.array_element(definitions.city_suffix);
},

street_suffix: function () {
return this.array_element(definitions.street_suffix());
return this.array_element(definitions.street_suffix);
},

br_state: function () {
return this.array_element(definitions.br_state());
return this.array_element(definitions.br_state);
},

br_state_abbr: function () {
return this.array_element(definitions.br_state_abbr());
return this.array_element(definitions.br_state_abbr);
},

us_state: function () {
return this.array_element(definitions.us_state());
return this.array_element(definitions.us_state);
},

us_state_abbr: function () {
return this.array_element(definitions.us_state_abbr());
return this.array_element(definitions.us_state_abbr);
},

uk_county: function () {
return this.array_element(definitions.uk_county());
return this.array_element(definitions.uk_county);
},

uk_country: function () {
return this.array_element(definitions.uk_country());
return this.array_element(definitions.uk_country);
},

first_name: function () {
return this.array_element(definitions.first_name());
return this.array_element(definitions.first_name);
},

last_name: function () {
return this.array_element(definitions.last_name());
return this.array_element(definitions.last_name);
},

name_prefix: function () {
return this.array_element(definitions.name_prefix());
return this.array_element(definitions.name_prefix);
},

name_suffix: function () {
return this.array_element(definitions.name_suffix());
return this.array_element(definitions.name_suffix);
},

catch_phrase_adjective: function () {
return this.array_element(definitions.catch_phrase_adjective());
return this.array_element(definitions.catch_phrase_adjective);
},

catch_phrase_descriptor: function () {
return this.array_element(definitions.catch_phrase_descriptor());
return this.array_element(definitions.catch_phrase_descriptor);
},

catch_phrase_noun: function () {
return this.array_element(definitions.catch_phrase_noun());
return this.array_element(definitions.catch_phrase_noun);
},

bs_adjective: function () {
return this.array_element(definitions.bs_adjective());
return this.array_element(definitions.bs_adjective);
},

bs_buzz: function () {
return this.array_element(definitions.bs_buzz());
return this.array_element(definitions.bs_buzz);
},

bs_noun: function () {
return this.array_element(definitions.bs_noun());
return this.array_element(definitions.bs_noun);
},

phone_formats: function () {
return this.array_element(definitions.phone_formats());
return this.array_element(definitions.phone_formats);
},

domain_suffix: function () {
return this.array_element(definitions.domain_suffix());
return this.array_element(definitions.domain_suffix);
}

};
Expand Down
3 changes: 0 additions & 3 deletions test/lorem.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ describe("lorem.js", function () {
describe("words()", function () {
beforeEach(function () {
sinon.spy(Faker.Helpers, 'shuffle');
sinon.spy(Faker.definitions, 'lorem');
});

afterEach(function () {
Faker.Helpers.shuffle.restore();
Faker.definitions.lorem.restore();
});

context("when no 'num' param passed in", function () {
Expand All @@ -23,7 +21,6 @@ describe("lorem.js", function () {
assert.ok(Array.isArray(words));
assert.equal(words.length, 3);
assert.ok(Faker.Helpers.shuffle.called);
assert.ok(Faker.definitions.lorem.called);
});
});

Expand Down

0 comments on commit b226b8d

Please sign in to comment.