Skip to content

Commit

Permalink
feat(refactor): Merge pull request #64 from pelias/refactor
Browse files Browse the repository at this point in the history
refactor code for performance & readability
  • Loading branch information
missinglink committed Jul 6, 2017
2 parents 1dde6fd + a5293ce commit fd3f9e0
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 1,110 deletions.
382 changes: 255 additions & 127 deletions Document.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions test/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ module.exports.tests.constructor = function(test) {
t.deepEqual(doc.center_point, {}, 'initial value');
t.true(Array.isArray(doc.category), 'initial value');
t.true(doc.hasOwnProperty('_meta'), 'initial value');
t.true(doc._meta.hasOwnProperty('version'), 'initial value');

// initialize 'parent' fields to empty arrays
t.equal(typeof doc.parent, 'object', 'initial value');
doc.getParentFields().forEach( function(field){
t.true(Array.isArray(doc.parent[field]), 'initial value');
});

// setters called
t.equal(doc.source, 'mysource', 'setter called');
Expand Down
3 changes: 1 addition & 2 deletions test/document/toESDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports.tests.toESDocument = function(test) {
_id: 'myid',
data: {
layer: 'mylayer',
parent: {},
source: 'mysource',
source_id: 'myid'
}
Expand All @@ -40,7 +39,7 @@ module.exports.tests.toESDocument = function(test) {
// downstream to elasticsearch.
t.false(esDoc.data.hasOwnProperty('address_parts'), 'does not include empty top-level maps');
t.false(esDoc.data.hasOwnProperty('category'), 'does not include empty top-level arrays');
t.false(esDoc.data.parent.hasOwnProperty('country'), 'does not include empty parent arrays');
t.false(esDoc.data.hasOwnProperty('parent'), 'does not include empty parent arrays');
t.end();
});
};
Expand Down
1 change: 0 additions & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var tests = [
require('./document/toESDocument.js'),
require('./DocumentMapperStream.js'),
require('./util/transform.js'),
require('./util/model.js'),
require('./util/valid.js'),
require('./serialize/test.js'),
];
Expand Down
77 changes: 2 additions & 75 deletions test/serialize/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,7 @@ module.exports.tests.minimal = function(test) {
'source_id': 'myid',
'name': {},
'phrase': {},
'parent': {
'borough': [],
'borough_a': [],
'borough_id': [],
'continent': [],
'continent_a': [],
'continent_id': [],
'country': [],
'country_a': [],
'country_id': [],
'county': [],
'county_a': [],
'county_id': [],
'dependency': [],
'dependency_a': [],
'dependency_id': [],
'localadmin': [],
'localadmin_a': [],
'localadmin_id': [],
'locality': [],
'locality_a': [],
'locality_id': [],
'macrocounty': [],
'macrocounty_a': [],
'macrocounty_id': [],
'macroregion': [],
'macroregion_a': [],
'macroregion_id': [],
'macrohood': [],
'macrohood_a': [],
'macrohood_id': [],
'neighbourhood': [],
'neighbourhood_a': [],
'neighbourhood_id': [],
'region': [],
'region_a': [],
'region_id': [],
'postalcode': [],
'postalcode_a': [],
'postalcode_id': []
},
'parent': {},
'address_parts': {},
'category': [],
'center_point': {}
Expand Down Expand Up @@ -136,45 +96,12 @@ module.exports.tests.complete = function(test) {

// WOF fields
'parent': {
'borough': [],
'borough_a': [],
'borough_id': [],
'continent': [],
'continent_a': [],
'continent_id': [],
'country': ['Great Britain'],
'country_a': ['GreatB'],
'country_id': ['1001'],
'county': [],
'county_a': [],
'county_id': [],
'dependency': [],
'dependency_a': [],
'dependency_id': [],
'localadmin': [],
'localadmin_a': [],
'localadmin_id': [],
'locality': [],
'locality_a': [],
'locality_id': [],
'macrocounty': [],
'macrocounty_a': [],
'macrocounty_id': [],
'macroregion': [],
'macroregion_a': [],
'macroregion_id': [],
'macrohood': [],
'macrohood_a': [],
'macrohood_id': [],
'neighbourhood': ['Shoreditch'],
'neighbourhood_a': [null],
'neighbourhood_id': ['2002'],
'region': [],
'region_a': [],
'region_id': [],
'postalcode': [],
'postalcode_a': [],
'postalcode_id': []
'neighbourhood_id': ['2002']
},

// geography
Expand Down
Loading

0 comments on commit fd3f9e0

Please sign in to comment.