diff --git a/src/Fable.React/Fable.Helpers.Isomorphic.fs b/src/Fable.React/Fable.Helpers.Isomorphic.fs index d2cf6943..cd397c15 100644 --- a/src/Fable.React/Fable.Helpers.Isomorphic.fs +++ b/src/Fable.React/Fable.Helpers.Isomorphic.fs @@ -33,8 +33,12 @@ open Fable.Helpers.React /// Isomorphic helper function for conditional executaion /// it will execute `clientFn model` on the client side and `serverFn model` on the server side -let inline isomorphicExec clientFn serverFn model = - ServerRenderingInternal.isomorphicExec clientFn serverFn model +let inline isomorphicExec (clientFn: 'a -> 'b) (serverFn: 'a -> 'b) (input: 'a) = +#if FABLE_COMPILER + clientFn input +#else + serverFn input +#endif let isomorphicView (clientView: 'model -> ReactElement) (serverView: 'model -> ReactElement) (model: 'model) = #if FABLE_COMPILER diff --git a/src/Fable.React/Fable.Helpers.React.fs b/src/Fable.React/Fable.Helpers.React.fs index 947fe539..bfb6d4ef 100644 --- a/src/Fable.React/Fable.Helpers.React.fs +++ b/src/Fable.React/Fable.Helpers.React.fs @@ -767,12 +767,6 @@ type ServerElementType = let [] private ChildrenName = "children" module ServerRenderingInternal = - let inline isomorphicExec (clientFn: 'a -> 'b) (serverFn: 'a -> 'b) (input: 'a) = -#if FABLE_COMPILER - clientFn input -#else - serverFn input -#endif #if FABLE_COMPILER let inline createServerElement (tag: obj, props: obj, children: ReactElement list, elementType: ServerElementType) = @@ -821,14 +815,11 @@ let inline from<[]'P> (com: ComponentClass<'P>) (props: 'P) (children: Rea /// Instantiate a component from a type inheriting React.Component /// Example: `ofType { myProps = 5 } []` let inline ofType<'T,[]'P,[]'S when 'T :> Component<'P,'S>> (props: 'P) (children: ReactElement list): ReactElement = - let inline clientRender () = - createElement(typedefof<'T>, props, children) - - let inline serverRender () = - createServerElement(typeof<'T>, props, children, ServerElementType.Component) - - isomorphicExec clientRender serverRender () - +#if FABLE_COMPILER + createElement(typedefof<'T>, props, children) +#else + createServerElement(typeof<'T>, props, children, ServerElementType.Component) +#endif /// OBSOLETE: Use `ofType` @@ -843,8 +834,11 @@ let inline com<'T,[]'P,[]'S when 'T :> Component<'P,'S>> (props: 'P) /// ofFunction Hello { name = "Maxime" } [] /// ``` let inline ofFunction<[]'P> (f: 'P -> ReactElement) (props: 'P) (children: ReactElement list): ReactElement = - isomorphicExec createElement createServerElementByFn (f, props, children) - +#if FABLE_COMPILER + createElement(f, props, children) +#else + createServerElementByFn(f, props, children) +#endif /// OBSOLETE: Use `ofFunction` [] @@ -915,41 +909,35 @@ let inline ofArray (els: ReactElement array): ReactElement = HTMLNode.List els : /// Instantiate a DOM React element let inline domEl (tag: string) (props: IHTMLProp list) (children: ReactElement list): ReactElement = - let inline clientRender (tag, props, children) = - createElement(tag, keyValueList CaseRules.LowerFirst props, children) - - let inline serverRender (tag, props, children) = - createServerElement(tag, (props |> Seq.cast), children, ServerElementType.Tag) - - isomorphicExec clientRender serverRender (tag, props, children) +#if FABLE_COMPILER + createElement(tag, keyValueList CaseRules.LowerFirst props, children) +#else + createServerElement(tag, (props |> Seq.cast), children, ServerElementType.Tag) +#endif /// Instantiate a DOM React element (void) let inline voidEl (tag: string) (props: IHTMLProp list) : ReactElement = - let inline clientRender (tag, props, children) = - createElement(tag, keyValueList CaseRules.LowerFirst props, children) - - let inline serverRender (tag, props, children) = - createServerElement(tag, (props |> Seq.cast), children, ServerElementType.Tag) - - isomorphicExec clientRender serverRender (tag, props, []) +#if FABLE_COMPILER + createElement(tag, keyValueList CaseRules.LowerFirst props, []) +#else + createServerElement(tag, (props |> Seq.cast), [], ServerElementType.Tag) +#endif /// Instantiate an SVG React element let inline svgEl (tag: string) (props: IProp list) (children: ReactElement list): ReactElement = - let inline clientRender (tag, props, children) = - createElement(tag, keyValueList CaseRules.LowerFirst props, children) - let inline serverRender (tag, props, children) = - createServerElement(tag, (props |> Seq.cast), children, ServerElementType.Tag) - - isomorphicExec clientRender serverRender (tag, props, children) +#if FABLE_COMPILER + createElement(tag, keyValueList CaseRules.LowerFirst props, children) +#else + createServerElement(tag, (props |> Seq.cast), children, ServerElementType.Tag) +#endif /// Instantiate a React fragment let inline fragment (props: IFragmentProp list) (children: ReactElement list): ReactElement = - let inline clientRender () = - createElement(typedefof, keyValueList CaseRules.LowerFirst props, children) - let inline serverRender () = - createServerElement(typedefof, (props |> Seq.cast), children, ServerElementType.Fragment) - - isomorphicExec clientRender serverRender () +#if FABLE_COMPILER + createElement(typedefof, keyValueList CaseRules.LowerFirst props, children) +#else + createServerElement(typedefof, (props |> Seq.cast), children, ServerElementType.Fragment) +#endif // Standard elements let inline a b c = domEl "a" b c