Skip to content

Commit

Permalink
Publish Fable.React 4.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Oct 16, 2018
1 parent 1d424cb commit 54453cc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/Fable.React/Fable.Helpers.Isomorphic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module Components =
inherit Component<HybridProps<'P>, HybridState>(initProps) with
do this.setInitState { isClient=false }

override x.componentDidMount() =
this.setState { isClient=true }
override __.componentDidMount() =
this.setState(fun _ _ -> { isClient=true })

override x.render() =
if x.state.isClient
Expand Down
25 changes: 15 additions & 10 deletions src/Fable.React/Fable.Helpers.React.fs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module rec Props =

type HTMLAttr =
| DefaultChecked of bool
| DefaultValue of string
| DefaultValue of obj
| Accept of string
| AcceptCharset of string
| AccessKey of string
Expand All @@ -188,8 +188,8 @@ module rec Props =
| ClassName of string
/// Alias of ClassName
| [<CompiledName("className")>] Class of string
| Cols of float
| ColSpan of float
| Cols of int
| ColSpan of int
| Content of string
| ContentEditable of bool
| ContextMenu of string
Expand Down Expand Up @@ -259,8 +259,8 @@ module rec Props =
| Rel of string
| Required of bool
| Role of string
| Rows of float
| RowSpan of float
| Rows of int
| RowSpan of int
| Sandbox of string
| Scope of string
| Scoped of bool
Expand All @@ -279,12 +279,12 @@ module rec Props =
| Start of float
| Step of obj
| Summary of string
| TabIndex of float
| TabIndex of int
| Target of string
| Title of string
| Type of string
| UseMap of string
| Value of string
| Value of obj
| Width of obj
| Wmode of string
| Wrap of string
Expand Down Expand Up @@ -1096,9 +1096,14 @@ let inline mountBySelector (domElSelector: string) (reactEl: ReactElement): unit

type Fable.Import.React.FormEvent with
/// Access the value from target
/// Equivalent to `unbox<string> this.target?value`
/// Equivalent to `(this.target :?> Browser.HTMLInputElement).value`
member this.Value =
unbox<string> this.target?value
(this.target :?> Browser.HTMLInputElement).value

/// Access the checked property from target
/// Equivalent to `(this.target :?> Browser.HTMLInputElement).checked`
member this.Checked =
(this.target :?> Browser.HTMLInputElement).``checked``

// Helpers for ReactiveComponents (see #44)
module ReactiveComponents =
Expand Down Expand Up @@ -1133,7 +1138,7 @@ type ReactiveCom<'P, 'S, 'Msg>(initProps) =
children = this.children }
this.props.view model (fun msg ->
let newState = this.props.update msg this.state.value
this.setState({ value = newState }))
this.setState(fun _ _ -> { value = newState }))

/// Renders a stateful React component from functions similar to Elmish
/// * `init` - Initializes component state with given props
Expand Down
57 changes: 29 additions & 28 deletions src/Fable.React/Fable.Helpers.ReactServer.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Fable.Helpers.ReactServer

open System
open System.IO
open System.Text.RegularExpressions

Expand Down Expand Up @@ -467,7 +466,7 @@ let inline objAttr (html:TextWriter) (key: string) (value: obj) = strAttr html k
let private renderHtmlAttr (html:TextWriter) (attr: HTMLAttr) =
match attr with
| DefaultChecked v | Checked v -> boolAttr html "checked" v
| DefaultValue v | Value v -> strAttr html "value" v
| DefaultValue v | Value v -> strAttr html "value" (string v)
| Accept v -> strAttr html "accept" v
| AcceptCharset v -> strAttr html "accept-charset" v
| AccessKey v -> strAttr html "accesskey" v
Expand Down Expand Up @@ -700,7 +699,7 @@ let private renderAttrs (html:TextWriter) (attrs: IProp seq) tag =
match tag, attr with
| "textarea", Value v
| "textarea", DefaultValue v ->
childHtml <- Some v
childHtml <- Some(string v)
| _, _ ->
html.Write ' '
renderHtmlAttr html attr
Expand All @@ -726,37 +725,39 @@ let inline private castHTMLNode (htmlNode: ReactElement): HTMLNode =
else
htmlNode :?> HTMLNode

let rec writeTo (html: TextWriter) (htmlNode: HTMLNode) : unit =
match htmlNode with
| HTMLNode.Text str -> escapeHtml html str
| HTMLNode.RawText str -> html.Write str
| HTMLNode.Node (tag, attrs, children) ->
html.Write '<'
html.Write tag
module Raw =
/// Writes the nodes into a TextWriter. DOESN'T ADD `reactroot` attribute.
let rec writeTo (html: TextWriter) (htmlNode: HTMLNode) : unit =
match htmlNode with
| HTMLNode.Text str -> escapeHtml html str
| HTMLNode.RawText str -> html.Write str
| HTMLNode.Node (tag, attrs, children) ->
html.Write '<'
html.Write tag

let child = renderAttrs html attrs tag
let child = renderAttrs html attrs tag

if voidTags.Contains tag then
html.Write "/>"
else
html.Write '>'
if voidTags.Contains tag then
html.Write "/>"
else
html.Write '>'

match child with
| Some c -> html.Write c
| None ->
for child in children do
writeTo html (castHTMLNode child)
match child with
| Some c -> html.Write c
| None ->
for child in children do
writeTo html (castHTMLNode child)

html.Write "</"
html.Write tag
html.Write '>'
| HTMLNode.List nodes ->
for node in nodes do
writeTo html (castHTMLNode node)
| HTMLNode.Empty -> ()
html.Write "</"
html.Write tag
html.Write '>'
| HTMLNode.List nodes ->
for node in nodes do
writeTo html (castHTMLNode node)
| HTMLNode.Empty -> ()

let renderToString (htmlNode: ReactElement): string =
let htmlNode = addReactMark (castHTMLNode htmlNode)
use html = new StringWriter()
htmlNode |> writeTo html
htmlNode |> Raw.writeTo html
html.ToString()
3 changes: 2 additions & 1 deletion src/Fable.React/Fable.React.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>4.0.1</Version>
<Version>4.1.1</Version>
<PackageVersion>4.1.1</PackageVersion>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Fable.React/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 4.1.1

* Mark `setState: 'S` as obsolete @SirUppyPancakes
* Enable writing into a TextWritter in SSR @thinkbeforecoding

### 4.0.1

* Update Fable 2 deps to stable version
Expand Down

0 comments on commit 54453cc

Please sign in to comment.