-
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.
handle composition with createComponent using combineRules
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { h } from 'snabbdom' | ||
import { combineRules } from 'fela' | ||
|
||
export default function createComponent(rules, selector = 'div') { | ||
return function(props, children) { | ||
const c = arguments.length === 1 ? props : children | ||
const p = arguments.length === 1 | ||
? { component: rules } | ||
: Object.assign({}, props, { component: rules }) | ||
return h(selector, p, c) | ||
if (typeof selector === 'string') { | ||
return h(selector, p, c) | ||
} | ||
const sel = selector(p, c) | ||
const mergedRules = combineRules(sel.data.component, rules) | ||
const pp = Object.assign({}, p, { component: mergedRules }) | ||
return h(sel.sel, pp, c) | ||
} | ||
} |
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