Skip to content

Commit a57f8a2

Browse files
Props and State must have PojoAttribute
1 parent fd61d4d commit a57f8a2

7 files changed

+67
-988
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
npm/
2+
.vscode/
23

34
## Ignore Visual Studio temporary files, build results, and
45
## files generated by popular Visual Studio add-ons.

RELEASE_NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 0.7.0-alpha.9
2+
3+
* React.Component type arguments must have PojoAttribute
4+
5+
### 0.7.0-alpha.8
6+
7+
* Compile children list as spread arguments
8+
19
### 0.7.0-alpha.6
210

311
* Compile with latest Fable alpha

build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var fable = require("fable-compiler");
66
var targets = {
77
all() {
88
return fable.promisify(fs.remove, "npm")
9-
.then(_ => fable.compile({ verbose: true }))
10-
// .then(_ => fable.compile({target: "umd"}))
9+
.then(_ => fable.compile())
10+
.then(_ => fable.compile({target: "umd"}))
1111
.then(_ => fable.promisify(fs.copy, "package.json", "npm/package.json"))
1212
.then(_ => fable.promisify(fs.copy, "README.md", "npm/README.md"))
1313
.then(_ => fable.promisify(fs.readFile, "RELEASE_NOTES.md"))

fableconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"sourceMaps": true,
66
"targets": {
77
"umd": {
8+
"dll": false,
89
"module": "umd",
9-
"outDir": "npm/umd"
10+
"outDir": "npm/umd",
11+
"refs": { "Fable.Core": "fable-core/umd" }
1012
}
1113
}
1214
}

src/Fable.React.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
</ItemGroup>
4545
<ItemGroup>
4646
<Reference Include="../node_modules/fable-core/Fable.Core.dll" />
47+
<!--<Reference Include="../../Fable/build/fable-core/Fable.Core.dll" />-->
4748
</ItemGroup>
4849
<ItemGroup>
4950
<Compile Include="react/Fable.Import.React.fs" />

src/react/Fable.Helpers.React.fs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ module Props =
298298
[<KeyValueList>]
299299
type Prop =
300300
| Key of string
301-
| Ref of (obj->unit)
301+
| Ref of (Browser.Element->unit)
302302
interface IHTMLProp
303303

304304
[<KeyValueList>]
@@ -578,44 +578,44 @@ open Props
578578
open Fable.AST
579579
open Fable.AST.Fable.Util
580580

581+
/// Only used internally to emit inline Fable AST
581582
type Emitter() =
582583
let createEl = makeImport "createElement" React
583-
let toPlainJsObj (expr: Fable.Expr) =
584-
CoreLibCall("Util", Some "toPlainJsObj", false, [expr])
585-
|> makeCall expr.Range expr.Type
586-
let (|CoreMeth|_|) coreMod meth = function
587-
| Fable.Value(Fable.ImportRef(meth', coreMod', Fable.CoreLib))
588-
when meth' = meth && coreMod' = coreMod -> Some CoreMeth
589-
| _ -> None
590-
let toArrayNonEmpty = function
591-
| Fable.Apply(CoreMeth "List" "default",[],_,_,_) ->
592-
Fable.Value Fable.Null
593-
| Fable.Apply(CoreMeth "List" "ofArray", [arr], Fable.ApplyMeth,_,_) -> arr
594-
| expr ->
595-
GlobalCall ("Array", Some "from", false, [expr])
596-
|> makeCall expr.Range (Fable.Array Fable.Any)
584+
let spread args =
585+
let inline (|CoreMeth|_|) coreMod meth = function
586+
| Fable.Value(Fable.ImportRef(meth', coreMod', Fable.CoreLib))
587+
when meth' = meth && coreMod' = coreMod -> Some CoreMeth
588+
| _ -> None
589+
let inline (|ArrayConst|_|) e =
590+
match e with
591+
| Fable.Value(Fable.ArrayConst(Fable.ArrayValues vals, _)) -> Some vals
592+
| _ -> None
593+
match args with
594+
| Fable.Apply(CoreMeth "List" "default",[],_,_,_) -> []
595+
| Fable.Apply(CoreMeth "List" "ofArray", [ArrayConst vals], Fable.ApplyMeth,_,_) -> vals
596+
| expr -> [Fable.Value(Fable.Spread expr)]
597597

598598
member x.Com(_com: Fable.ICompiler, i: Fable.ApplyInfo) =
599599
let args =
600600
match i.args with
601601
| [props; children] ->
602602
let com = makeNonGenTypeRef i.methodTypeArgs.Head
603-
[com; toPlainJsObj props; toArrayNonEmpty children]
603+
[com; props] @ spread children
604604
| _ -> failwith "Unexpected arguments"
605605
Fable.Apply(createEl, args, Fable.ApplyMeth, i.returnType, i.range)
606606
member x.From(_com: Fable.ICompiler, i: Fable.ApplyInfo) =
607607
let args =
608608
match i.args with
609609
| [com; props; children] ->
610-
[com; toPlainJsObj props; toArrayNonEmpty children]
610+
[com; props] @ spread children
611611
| _ -> failwith "Unexpected arguments"
612612
Fable.Apply(createEl, args, Fable.ApplyMeth, i.returnType, i.range)
613613

614614
member x.DomEl(_com: Fable.ICompiler, i: Fable.ApplyInfo) =
615615
let args =
616616
match i.args with
617617
| [tag; props; children] ->
618-
[tag; props; toArrayNonEmpty children]
618+
[tag; props] @ spread children
619619
| _ -> failwith "Unexpected arguments"
620620
Fable.Apply(createEl, args, Fable.ApplyMeth, i.returnType, i.range)
621621

@@ -624,29 +624,31 @@ type Emitter() =
624624
match i.args with
625625
| [props; children] ->
626626
let tag = Fable.Value(Fable.StringConst tag)
627-
[tag; props; toArrayNonEmpty children]
627+
[tag; props] @ spread children
628628
| _ -> failwith "Unexpected arguments"
629629
Fable.Apply(createEl, args, Fable.ApplyMeth, i.returnType, i.range)
630630

631+
open Fable.Import.React
632+
631633
/// Instantiate a React component from a type inheriting React.Component<>
632634
[<Emit(typeof<Emitter>, "Com")>]
633-
let com<'T,'P,'S when 'T :> React.Component<'P,'S>> (props: 'P) (children: React.ReactElement<obj> list): React.ReactElement<obj> = jsNative
635+
let com<'T,'P,'S when 'T :> Component<'P,'S>> (props: 'P) (children: ReactElement list): ReactElement = jsNative
634636
/// Instantiate a stateless component from a function
635637
636638
[<Emit(typeof<Emitter>, "From")>]
637-
let fn (f: 'Props -> #React.ReactElement<obj>) (props: 'Props) (children: React.ReactElement<obj> list): React.ReactElement<obj> = jsNative
639+
let fn<[<Pojo>]'P> (f: 'P -> ReactElement) (props: 'P) (children: ReactElement list): ReactElement = jsNative
638640

639641
/// Instantiate an imported React component
640642
[<Emit(typeof<Emitter>, "From")>]
641-
let from<'P> (com: React.ComponentClass<'P>) (props: 'P) (children: React.ReactElement<obj> list): React.ReactElement<obj> = jsNative
643+
let from<[<Pojo>]'P> (com: ComponentClass<'P>) (props: 'P) (children: ReactElement list): ReactElement = jsNative
642644

643645
/// Instantiate a DOM React element
644646
[<Emit(typeof<Emitter>, "DomEl")>]
645-
let domEl (tag: string) (props: IHTMLProp list) (children: React.ReactElement<obj> list): React.ReactElement<obj> = jsNative
647+
let domEl (tag: string) (props: IHTMLProp list) (children: ReactElement list): ReactElement = jsNative
646648

647649
/// Instantiate an SVG React element
648650
[<Emit(typeof<Emitter>, "DomEl")>]
649-
let svgEl (tag: string) (props: #IProp list) (children: React.ReactElement<obj> list): React.ReactElement<obj> = jsNative
651+
let svgEl (tag: string) (props: #IProp list) (children: ReactElement list): ReactElement = jsNative
650652

651653
[<Emit(typeof<Emitter>, "Tagged", "a")>]
652654
let a b c = domEl "a" b c
@@ -914,6 +916,6 @@ let text b c = svgEl "text" b c
914916
let tspan b c = svgEl "tspan" b c
915917

916918
/// Cast a string to a React element (erased in runtime)
917-
let [<Emit("$0")>] str (s: string): React.ReactElement<obj> = unbox s
919+
let [<Emit("$0")>] str (s: string): ReactElement = unbox s
918920
/// Cast an option value to a React element (erased in runtime)
919-
let [<Emit("$0")>] opt (o: React.ReactElement<obj> option): React.ReactElement<obj> = unbox o
921+
let [<Emit("$0")>] opt (o: ReactElement option): ReactElement = unbox o

0 commit comments

Comments
 (0)