Skip to content

Commit

Permalink
2.3.0 All fela renderer options
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael committed Mar 14, 2019
1 parent 41bf1ac commit fef5e1c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ Included as deps:
[More about enhancers.](https://fela.js.org/docs/advanced/Enhancers.html)
[I suggest to look at this one first.](https://github.com/rofrischmann/fela/tree/master/packages/fela-monolithic)

```javascript
*In the options object below you can also add [other Renderer options](https://fela.js.org/docs/advanced/RendererConfiguration.html)*

```javascript
const options = {
// Not required. Default styles to mix. Does not mix if omitted.
// Either pass a function (then key would be `fdef`):
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"prod:es": "cross-env NODE_ENV=production BUILD=es rollup -c",
"prod": "npm run prod:es && npm run prod:cjs"
},
"version": "2.2.1",
"version": "2.3.0",
"ava": {
"files": [
"./test/specs/*.ts"
Expand Down
28 changes: 18 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ const defaultOpts = {
ssr: false
}

const types = Object.freeze({ f: 'function', o: 'object', s: 'string' })

const getRules = (() => {
const always = (a: any) => () => a
const reflect = (a: any) => a
const types = { f: 'function', o: 'object', s: 'string' }
const camelify = (str: string) => str.replace(/-(\w)/gu, (_s, l) => l.toUpperCase())
const pickStyle = (style: AnyObject, name: string) => {
return style ? (
Expand Down Expand Up @@ -86,35 +87,42 @@ class Renderer {
return renderToMarkup(this.renderer)
}
constructor(opts: Partial<Options> = {}) {
const { method, ssr, preset, plugins, enhancers } = { ...defaultOpts, ...opts }
const {
method,
ssr,
preset,
plugins,
enhancers,
...miscRenderOpts
} = { ...defaultOpts, ...opts }
const presetConfig = { ...defaultOpts.preset, ...(preset || {}) }

if((opts as any).fdef) {
throw new Error('fela-vue: Change deprecated `fdef` to `defStyles`!')
}

// Fela renderer creation.
this.renderer = createRenderer({
this.renderer = createRenderer({
...miscRenderOpts,
enhancers,
plugins: [
embedded(),
prefixer(),
fallback(),
unit(...presetConfig.unit),
...plugins
],
]
})
const { renderer } = this

// Default styles.
const fdef = opts.defStyles as any
let fdefKey: string, fdefValue: Function
let fdefKey: string, fdefValue: (vm?: AnyObject) => AnyObject

if(fdef) {
;[fdefKey, fdefValue] = {
'object': [fdef.key, fdef.value],
'function': ['fdef', fdef]
}[typeof fdef]
switch(typeof fdef) {
case types.o: [fdefKey, fdefValue] = [fdef.key, fdef.value]; break
case types.f: [fdefKey, fdefValue] = ['fdef', fdef]; break
default: break
}

// Fela mounting.
Expand Down

0 comments on commit fef5e1c

Please sign in to comment.