Skip to content
Permalink
Browse files

fix(datatable): and kick json-statham again. still won't bundle

  • Loading branch information...
doktordirk committed Jul 30, 2016
1 parent 86ce0ae commit c2f5407e0b872a350b110db59b3e874e56b22b20
Showing with 42 additions and 12 deletions.
  1. +0 −1 bower.json
  2. +0 −5 config.js
  3. +0 −3 package.json
  4. +42 −3 src/datatable.js
@@ -30,7 +30,6 @@
"aurelia-router": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"aurelia-view-manager": "^0.0.5",
"json-statham": "^1.6.0",
"typer": "^1.1.0"
}
}
@@ -17,7 +17,6 @@ System.config({
"aurelia-templating": "npm:aurelia-templating@1.0.0",
"aurelia-view-manager": "npm:aurelia-view-manager@0.0.5",
"fetch": "github:github/fetch@1.0.0",
"json-statham": "npm:json-statham@1.6.0",
"typer": "npm:typer@1.1.0",
"npm:aurelia-api@3.0.0-rc4": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0",
@@ -113,10 +112,6 @@ System.config({
"aurelia-logging": "npm:aurelia-logging@1.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0",
"extend": "npm:extend@3.0.0"
},
"npm:json-statham@1.6.0": {
"extend": "npm:extend@3.0.0",
"systemjs-json": "github:systemjs/plugin-json@0.1.2"
}
}
});
@@ -44,7 +44,6 @@
"aurelia-router": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"aurelia-view-manager": "^0.0.5",
"json-statham": "^1.6.0",
"typer": "^1.1.0"
},
"peerDependencies": {
@@ -55,7 +54,6 @@
"aurelia-router": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"aurelia-view-manager": "^0.0.5",
"json-statham": "^1.6.0",
"typer": "^1.1.0"
},
"devDependencies": {
@@ -72,7 +70,6 @@
"aurelia-router": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"aurelia-view-manager": "^0.0.5",
"json-statham": "^1.6.0",
"typer": "^1.1.0"
},
"devDependencies": {
@@ -2,7 +2,6 @@ import {bindable, inject, computedFrom, customElement, bindingMode} from 'aureli
import {resolvedView} from 'aurelia-view-manager';
import {EntityManager} from 'aurelia-orm';
import {Router} from 'aurelia-router';
import {Statham} from 'json-statham';

@customElement('datatable')
@resolvedView('spoonx/datatable', 'datatable')
@@ -240,7 +239,47 @@ export class DataTable {
return this.populate.replace(' ', '').split(',').indexOf(column) === -1;
}

displayValue(row, propertyName) {
return new Statham(row, Statham.MODE_NESTED).fetch(propertyName);
displayValue(row, ...propertyName) {
return fetchFrom(row, ...normalizeKey(...propertyName));
}
}

/**
* Used to normalize keys of mixed array and dot-separated string to a single array of undotted strings
* @param {string|Array<keys>} keys (dot-separated) string(s) or array of keys
* @param {Array} ...rest Rest of the arguments
* @return {Array} that The key normalized to an array of strings
*/
function normalizeKey(key, ...rest) {
/*
* First, we split the arguments in key and rest
* then, if key is an array, we need to normalize it as well
* else it can be split into an array directly
* if the rest was empty, we're done
* if not we concat our normalized key with the normalized rest
*/
let normalized = Array.isArray(key) ? normalizeKey(...key) : key.split('.');

return rest.length === 0 ? normalized : normalized.concat(normalizeKey(...rest));
}


/**
* Fetches value from (nested) object with a normalized key
* @param {Object} data The data to fetch data from
* @param {string|Array<string>} keys string or array of keys
* @param {Array<string>} ...rest Rest of the arguments
* @return {any} that The retrieved value from the data
*/
function fetchFrom(data, key, ...rest) {
/*
* data is the POJO of the current branch
* [key,...rest] is the current normalized key,
* thus key is the first key as string and ...rest the remainder of the key
* if rest is empty, then data[key] is the data we want to fetch
* else, we go down onw set on the branch (data[key]) and repeat with ...rest,
* which will make the new key the first entry of ...rest
* and the new rest the remainder of ...rest minus the key
*/
return rest.length === 0 ? data[key] : fetchFrom(data[key], ...rest);
}

0 comments on commit c2f5407

Please sign in to comment.
You can’t perform that action at this time.