From 5fe54e0b27bf446c6d5f5d5c87074047ceff1036 Mon Sep 17 00:00:00 2001 From: Christer van der Meeren Date: Sun, 26 Jan 2020 14:18:03 +0100 Subject: [PATCH] Switch to custom unflatten implementation #39 https://github.com/hughsk/flat/issues/94 --- README.md | 5 ++++ docs-app/package-lock.json | 15 ---------- docs-app/package.json | 1 - src/Feliz.Generator.MaterialUI/ApiParser.fs | 2 +- src/Feliz.MaterialUI/Bindings.fs | 6 ---- src/Feliz.MaterialUI/Feliz.MaterialUI.fsproj | 8 ++--- src/Feliz.MaterialUI/FlatBindings.fs | 27 ----------------- src/Feliz.MaterialUI/Flatten.fs | 31 ++++++++++++++++++++ src/Feliz.MaterialUI/Mui.fs | 4 +-- src/Feliz.MaterialUI/Styles.fs | 6 ++-- 10 files changed, 45 insertions(+), 60 deletions(-) delete mode 100644 src/Feliz.MaterialUI/FlatBindings.fs create mode 100644 src/Feliz.MaterialUI/Flatten.fs diff --git a/README.md b/README.md index 4b95568..04dc32f 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,11 @@ To run targets using Fake: `dotnet fake build -t TargetName` Changelog --------- +### 0.11.0 + +* Switched to custom unflatten implementation to avoid problems (see [#39](https://github.com/cmeeren/Feliz.MaterialUI/issues/39) and [hughsk/flat#94](https://github.com/hughsk/flat/issues/94)) +- As a consequence of the above, removed (the read-only) `Theme.props` and `Theme.overrides` + ### 0.10.1 * Fixed higher-arity `theme.spacing` overloads diff --git a/docs-app/package-lock.json b/docs-app/package-lock.json index 9768df3..d817f4d 100644 --- a/docs-app/package-lock.json +++ b/docs-app/package-lock.json @@ -4606,21 +4606,6 @@ "resolve-dir": "^1.0.1" } }, - "flat": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.0.tgz", - "integrity": "sha512-6KSMM+cHHzXC/hpldXApL2S8Uz+QZv+tq5o/L0KQYleoG+GcwrnIJhTWC7tCOiKQp8D/fIvryINU1OZCCwevjA==", - "requires": { - "is-buffer": "~2.0.4" - }, - "dependencies": { - "is-buffer": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", - "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" - } - } - }, "flush-write-stream": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/flush-write-stream/-/flush-write-stream-1.1.1.tgz", diff --git a/docs-app/package.json b/docs-app/package.json index 918ac19..b28fc15 100644 --- a/docs-app/package.json +++ b/docs-app/package.json @@ -11,7 +11,6 @@ "@material-ui/core": "^4.8.3", "@material-ui/icons": "^4.5.1", "@material-ui/lab": "^4.0.0-alpha.39", - "flat": "^5.0.0", "gh-pages": "^2.2.0", "mdi-material-ui": "^6.10.0", "react": "^16.12.0", diff --git a/src/Feliz.Generator.MaterialUI/ApiParser.fs b/src/Feliz.Generator.MaterialUI/ApiParser.fs index 7d68416..2f5e2c0 100644 --- a/src/Feliz.Generator.MaterialUI/ApiParser.fs +++ b/src/Feliz.Generator.MaterialUI/ApiParser.fs @@ -799,7 +799,7 @@ let parseApi () = ComponentApi.create "Feliz.MaterialUI" "Mui" |> ComponentApi.addComponent themeProvider |> ComponentApi.addComponents (components |> List.map (fun c -> c.GeneratorComponent)) - |> ComponentApi.setParseProps "createObj !!properties |> Flat.flat.unflatten" + |> ComponentApi.setParseProps "!!properties |> Object.fromFlatEntries" { GeneratorComponentApi = api diff --git a/src/Feliz.MaterialUI/Bindings.fs b/src/Feliz.MaterialUI/Bindings.fs index fe3d854..4e74494 100644 --- a/src/Feliz.MaterialUI/Bindings.fs +++ b/src/Feliz.MaterialUI/Bindings.fs @@ -311,13 +311,7 @@ type Theme = abstract breakpoints: Breakpoints abstract direction: Direction abstract mixins: Mixins - [] - abstract overridesObj: obj - member inline this.overrides = this.overridesObj |> Flat.flat.flatten |> objectEntries |> unbox abstract palette: Palette - [] - abstract propsObj: obj - member inline this.props = this.propsObj |> Flat.flat.flatten |> objectEntries |> unbox abstract shadows: string [] abstract typography: Typography abstract spacing: a: int -> int diff --git a/src/Feliz.MaterialUI/Feliz.MaterialUI.fsproj b/src/Feliz.MaterialUI/Feliz.MaterialUI.fsproj index 95b36ae..87ec057 100644 --- a/src/Feliz.MaterialUI/Feliz.MaterialUI.fsproj +++ b/src/Feliz.MaterialUI/Feliz.MaterialUI.fsproj @@ -5,13 +5,14 @@ true Feliz-style Fable bindings for Material-UI. Christer van der Meeren - 0.10.1 - Fixed higher-arity theme.spacing overloads + 0.11.0 + - Switched to custom unflatten implementation to avoid problems +- As a consequence of the above, removed (the read-only) Theme.props and Theme.overrides - + @@ -30,7 +31,6 @@ - diff --git a/src/Feliz.MaterialUI/FlatBindings.fs b/src/Feliz.MaterialUI/FlatBindings.fs deleted file mode 100644 index 2f163b4..0000000 --- a/src/Feliz.MaterialUI/FlatBindings.fs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Feliz.MaterialUI - -open System.ComponentModel -open Fable.Core.JsInterop - - -[] -type FlatOptions = - abstract delimiter: string with get, set - abstract safe: bool with get, set - abstract object: bool with get, set - abstract overwrite: bool with get, set - abstract maxDepth: int with get, set - abstract transformKey: string -> string with get, set - - -[] -type Flat = - abstract flatten: original: obj * ?options: FlatOptions -> obj - abstract unflatten: original: obj * ?options: FlatOptions -> obj - - - -[] -module Flat = - - let flat : Flat = importDefault "flat" diff --git a/src/Feliz.MaterialUI/Flatten.fs b/src/Feliz.MaterialUI/Flatten.fs new file mode 100644 index 0000000..7608c43 --- /dev/null +++ b/src/Feliz.MaterialUI/Flatten.fs @@ -0,0 +1,31 @@ +namespace Feliz.MaterialUI + +module internal Object = + + open Fable.Core + open Fable.Core.JS + open Fable.Core.JsInterop + + [] + let fromFlatEntries (kvs: seq) : obj = jsNative diff --git a/src/Feliz.MaterialUI/Mui.fs b/src/Feliz.MaterialUI/Mui.fs index aad70c3..4865436 100644 --- a/src/Feliz.MaterialUI/Mui.fs +++ b/src/Feliz.MaterialUI/Mui.fs @@ -20,10 +20,10 @@ module MuiHelpers = import "createElement" "react" let createElement (el: ReactElementType) (properties: IReactProperty seq) : ReactElement = - reactElement el (createObj !!properties |> Flat.flat.unflatten) + reactElement el (!!properties |> Object.fromFlatEntries) let createElementTag (tag: string) (properties: IReactProperty seq) : ReactElement = - reactElementTag tag (createObj !!properties |> Flat.flat.unflatten) + reactElementTag tag (!!properties |> Object.fromFlatEntries) [] type Mui = diff --git a/src/Feliz.MaterialUI/Styles.fs b/src/Feliz.MaterialUI/Styles.fs index dd46440..2d9c0c1 100644 --- a/src/Feliz.MaterialUI/Styles.fs +++ b/src/Feliz.MaterialUI/Styles.fs @@ -85,10 +85,8 @@ type Styles = /// Generate a theme base on the configured incomplete theme object. static member inline createMuiTheme (props: IThemeProp list) : Theme = - props - |> unbox - |> createObj - |> Flat.flat.unflatten + !!props + |> Object.fromFlatEntries :?> Theme |> StyleImports.createMuiTheme