Skip to content

Commit

Permalink
Switch to custom unflatten implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeeren committed Jan 26, 2020
1 parent 6f2d489 commit 5fe54e0
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 60 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions docs-app/package-lock.json

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

1 change: 0 additions & 1 deletion docs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Feliz.Generator.MaterialUI/ApiParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/Feliz.MaterialUI/Bindings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,7 @@ type Theme =
abstract breakpoints: Breakpoints
abstract direction: Direction
abstract mixins: Mixins
[<Emit("$0.overrides"); EditorBrowsable(EditorBrowsableState.Never)>]
abstract overridesObj: obj
member inline this.overrides = this.overridesObj |> Flat.flat.flatten |> objectEntries |> unbox<IThemeProp []>
abstract palette: Palette
[<Emit("$0.props"); EditorBrowsable(EditorBrowsableState.Never)>]
abstract propsObj: obj
member inline this.props = this.propsObj |> Flat.flat.flatten |> objectEntries |> unbox<IThemeProp []>
abstract shadows: string []
abstract typography: Typography
abstract spacing: a: int -> int
Expand Down
8 changes: 4 additions & 4 deletions src/Feliz.MaterialUI/Feliz.MaterialUI.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>Feliz-style Fable bindings for Material-UI.</Description>
<Authors>Christer van der Meeren</Authors>
<Version>0.10.1 </Version>
<PackageReleaseNotes>Fixed higher-arity theme.spacing overloads</PackageReleaseNotes>
<Version>0.11.0 </Version>
<PackageReleaseNotes>- Switched to custom unflatten implementation to avoid problems
- As a consequence of the above, removed (the read-only) Theme.props and Theme.overrides</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<None Include="paket.template" />
<Compile Include="FlatBindings.fs" />
<Compile Include="Flatten.fs" />
<Compile Include="Misc.fs" />
<Compile Include="Bindings.fs" />
<Compile Include="Autocomplete.fs" />
Expand All @@ -30,7 +31,6 @@
<NpmDependencies>
<NpmPackage Name="@material-ui/core" Version="gte 4.8 lt 5" ResolutionStrategy="max" />
<NpmPackage Name="@material-ui/lab" Version="4.0.0-alpha.39" />
<NpmPackage Name="flat" Version="gte 5 lt 6" ResolutionStrategy="max" />
</NpmDependencies>
</PropertyGroup>

Expand Down
27 changes: 0 additions & 27 deletions src/Feliz.MaterialUI/FlatBindings.fs

This file was deleted.

31 changes: 31 additions & 0 deletions src/Feliz.MaterialUI/Flatten.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Feliz.MaterialUI

module internal Object =

open Fable.Core
open Fable.Core.JS
open Fable.Core.JsInterop

[<Emit("""
function setProperty(target, key, value) {
const sepIdx = key.indexOf('.')
if (sepIdx === -1) {
target[key] = value
} else {
const topKey = key.substring(0, sepIdx)
const nestedKey = key.substring(sepIdx + 1)
if (target[topKey] === undefined) {
target[topKey] = {}
}
setProperty(target[topKey], nestedKey, value)
}
}
const target = {}
for (let kv of $0) {
setProperty(target, kv[0], kv[1])
}
return target
""")>]
let fromFlatEntries (kvs: seq<string * obj>) : obj = jsNative
4 changes: 2 additions & 2 deletions src/Feliz.MaterialUI/Mui.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

[<Erase>]
type Mui =
Expand Down
6 changes: 2 additions & 4 deletions src/Feliz.MaterialUI/Styles.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5fe54e0

Please sign in to comment.