-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7490e2f
commit a6c27e2
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Field mapper class for rendering patterns. | ||
* | ||
* @constructor | ||
* @param {Object} item - object containing the data to be rendered | ||
* @param {Object} mapping - object containing the mapping | ||
*/ | ||
|
||
iq_progessive_decoupler_FieldMapper = function (item, mapping) { | ||
var self = this; | ||
self.item = item; | ||
self.mapping = mapping; | ||
|
||
/** | ||
* Apply mapping to item | ||
*/ | ||
self.applyMappging = function (item = self.item, mapping = self.mapping) { | ||
let output = {}; | ||
Object.keys(mapping).forEach(function(key){ | ||
output[key] = self.mapField(item, mapping[key]); | ||
}); | ||
return output; | ||
}; | ||
|
||
|
||
/** | ||
* Apply mapping to item | ||
*/ | ||
self.mapField = function (item, mapping) { | ||
if (mapping.type == 'static') { | ||
return mapping.value; | ||
} | ||
if (mapping.type == 'array') { | ||
var arrayItem = eval(mapping.value); | ||
arrayItem = arrayItem.map(function(item){ | ||
return self.applyMappging(item, mapping.mapping); | ||
}); | ||
return arrayItem; | ||
} | ||
return eval(mapping.value); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters