Skip to content

Commit

Permalink
fix: support isMedia on onWhen
Browse files Browse the repository at this point in the history
  • Loading branch information
Darío Javier Cravero committed Oct 23, 2019
1 parent d08c35e commit 2956867
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions morph/react/block-off-when.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getProp, isList, isStory } from '../utils.js'

let IS_MEDIA = /(!?props\.isMedia)(.+)/

export function enter(node, parent, state) {
if (node.isFragment && node.children.length === 0) return

Expand Down Expand Up @@ -36,6 +38,9 @@ export function enter(node, parent, state) {
default:
break
}
} else if (IS_MEDIA.test(value)) {
let [, variable, media] = value.match(IS_MEDIA)
value = `${variable.replace('props.', '')}.${media.toLowerCase()}`
}
state.render.push(`${value} ? `)
} else if (isStory(node, state)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viewstools/morph",
"version": "19.10.9",
"version": "19.10.10",
"description": "Views language morpher",
"main": "bin.js",
"type": "module",
Expand Down
4 changes: 4 additions & 0 deletions parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ That would mean that SomeView in ${block.name} will be replaced by ${block.name}
})
}

if (name === 'onWhen' && /!?isMedia.+/.test(slotName)) {
useIsMedia = true
}

if (name === 'format') {
block.format = getFormat(value)
}
Expand Down

0 comments on commit 2956867

Please sign in to comment.