Skip to content

Instantly share code, notes, and snippets.

@aph5nt
Created August 8, 2016 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aph5nt/05598cfe59162646dc54f491773474d7 to your computer and use it in GitHub Desktop.
Save aph5nt/05598cfe59162646dc54f491773474d7 to your computer and use it in GitHub Desktop.
sample amplify w# binding
namespace Amplify
open WebSharper
open WebSharper.JavaScript
open WebSharper.InterfaceGenerator
open WebSharper.JQuery
module Definition =
let DefineRequestType =
"ajax".Split ' ' |> Pattern.EnumStrings "DefineRequestType"
let RequestSettings =
Pattern.Config "RequestSettings" {
Required =
[
"resourceId" , T<string>
]
Optional =
[
"data", T<obj>
"success" , (T<obj>?data ^-> T<unit>)
"error" , (T<string>?status * T<string>?xhr ^-> T<unit>)
]
}
let Request =
Class "Request"
|+> Static [
"Define" => ( T<string>?resourceId * DefineRequestType?requestType * T<AjaxSettings>?settings ^-> T<unit> )
]
let Amplify =
Class "Amplify"
|+> Static [
"Request" => (RequestSettings?settings ^-> T<unit>)
"Request" => (T<string>?resourceId * T<Object<string>>?data * (T<obj> ^-> T<unit>)?callback ^-> T<unit>)
"Define" => ( T<string>?resourceId * DefineRequestType?requestType * T<AjaxSettings>?settings ^-> T<unit> )
]
|=> Nested [ Request ]
let Assembly =
Assembly [
Namespace "WebSharper.Amplify" [
Amplify
RequestSettings
DefineRequestType
]
Namespace "WebSharper.Amplify.Resources" [
Resource "Amplify" "https://cdnjs.cloudflare.com/ajax/libs/amplifyjs/1.1.2/amplify.core.js"
|> fun r -> r.AssemblyWide()
]
]
[<Sealed>]
type Amplify() =
interface IExtension with
member ext.Assembly =
Definition.Assembly
[<assembly: Extension(typeof<Amplify>)>]
do ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment