Skip to content

Commit

Permalink
Merge branch 'jvanbruegge/patch-2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Swizz committed May 22, 2017
2 parents 7b10ac2 + 48e0099 commit 5ac26f2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
17 changes: 16 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ var deepifyKeys = function (obj) { return mapObject(obj,
}
); };

var renameMod = function (name) {
switch (name) {
case 'data': return 'dataset'
default: return name
}
};

var flatifyKeys = function (obj) { return mapObject(obj,
function (ref) {
var mod = ref[0];
Expand Down Expand Up @@ -132,7 +139,15 @@ var considerSvg = function (vnode$$1) { return !svg(vnode$$1) ? vnode$$1 :
}
); };

var considerDataAria = function (data) { return mapObject(data,
var considerDataAria = function (data) { return mapObject(
mapObject(data, function (ref) {
var mod = ref[0];
var data = ref[1];

var key = renameMod(mod);
return (( obj = {}, obj[key] = data, obj ))
var obj;
}),
function (ref) {
var mod = ref[0];
var data = ref[1];
Expand Down
7 changes: 7 additions & 0 deletions src/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export const deepifyKeys = (obj) => mapObject(obj,
)
)

export const renameMod = (name) => {
switch (name) {
case 'data': return 'dataset'
default: return name
}
}

export const flatifyKeys = (obj) => mapObject(obj,
([mod, data]) => !is.object(data) ? ({ [mod]: data }) : mapObject(
flatifyKeys(data),
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const considerSvg = (vnode) => !is.svg(vnode) ? vnode :
}
)

const considerDataAria = (data) => fn.mapObject(data,
const considerDataAria = (data) => fn.mapObject(
fn.mapObject(data, ([mod, data]) => {
const key = fn.renameMod(mod)
return ({ [key]: data })
}),
([mod, data]) => !['data', 'aria'].includes(mod) ? { [mod]: data } :
fn.flatifyKeys({ [mod]: data })
)
Expand Down
2 changes: 1 addition & 1 deletion test/snabbdom-specs/vnode-data-aria-object/expected.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

export default (h) => {
return h('div', {
props: { 'data-color': 'red', 'data-hidden': true }
dataset: { color: 'red', hidden: true }
}, [])
}
3 changes: 2 additions & 1 deletion test/snabbdom-specs/vnode-data-aria/expected.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

export default (h) => {
return h('div', {
props: { 'data-color': 'red', 'aria-hidden': true }
dataset: { color: 'red' },
props: { 'aria-hidden': true }
}, [])
}

0 comments on commit 5ac26f2

Please sign in to comment.