Replace "obj" with JSMap typ which emulates Map but is backed by a plain
JS object
This commit is contained in:
1 parent
3f1d98a613
commit
32ff893f99
5 files changed
+85
-33
No files matched your search
@@ -1,6 +1,7 @@
|
||||
// Generated code -- You probably should not edit
|
||||
namespace rec {{package}}
|
||||
open Fable.Core
|
||||
open JSMap
|
||||
open google.protobuf
|
||||
|
||||
{{#each enum_type}}
|
||||
@@ -28,8 +29,7 @@ type {{name}} =
|
||||
{
|
||||
{{#each field}}
|
||||
{{#if type.isdict}}
|
||||
// Use Fable.Core.DynamicExtensions
|
||||
{{fsescape nAme}} : obj
|
||||
{{fsescape nAme}} : JSMap<{{type.fstype}}>
|
||||
{{else}}
|
||||
{{#if type.islist}}
|
||||
{{fsescape nAme}} : {{type.fstype}}[]
|
||||
|
||||
@@ -66,7 +66,7 @@ module Accounts =
|
||||
investmentDecisionId = ""
|
||||
executionDecisionId = ""
|
||||
clientId = ""
|
||||
miscTags = obj()
|
||||
miscTags = JSMap.empty<string>
|
||||
}
|
||||
iceAccountData =
|
||||
{ nybitHouse=""
|
||||
|
||||
@@ -11,7 +11,6 @@ open System.Xml
|
||||
open Fable.PowerPack.PromiseImpl
|
||||
open bts.api.admin
|
||||
open Global
|
||||
open Fable.Core.DynamicExtensions
|
||||
|
||||
let getAdminData (admin:IAdminService) =
|
||||
Cmd.ofPromise
|
||||
@@ -40,7 +39,7 @@ let defaultScratchUser = {
|
||||
}
|
||||
userData =
|
||||
{
|
||||
accountPermissions = { accountPermissions = obj() }
|
||||
accountPermissions = { accountPermissions = JSMap.empty<UserAccountPermissionUnit> }
|
||||
exchangeUserData =
|
||||
{
|
||||
cmeData = {
|
||||
@@ -49,7 +48,7 @@ let defaultScratchUser = {
|
||||
smpId = ""
|
||||
textA = ""
|
||||
textB = ""
|
||||
miscTags = Map.empty
|
||||
miscTags = JSMap.empty<string>
|
||||
smpInstruction = ""
|
||||
maxOrderRatePerConnection = ""
|
||||
}
|
||||
@@ -136,8 +135,6 @@ let createUser (admin:IAdminService) (user:BTSUser) = promise {
|
||||
return ErrorOccured (sprintf "Error creating user: %s" result.errorText)
|
||||
}
|
||||
|
||||
let mapMiscTags (str:string) = ofJson<obj> str
|
||||
|
||||
let applyUpdate (field:UserField) (user:BTSUser) =
|
||||
match field with
|
||||
| Name n -> { user with name = n }
|
||||
@@ -148,7 +145,9 @@ let applyUpdate (field:UserField) (user:BTSUser) =
|
||||
| SMPID smpid -> { user with userData = { user.userData with exchangeUserData = { user.userData.exchangeUserData with cmeData = { user.userData.exchangeUserData.cmeData with smpId = smpid }}}}
|
||||
| SMPInstruction smpi -> { user with userData = { user.userData with exchangeUserData = { user.userData.exchangeUserData with cmeData = { user.userData.exchangeUserData.cmeData with smpInstruction = smpi }}}}
|
||||
| MaxOrderRatePerConnection morpc -> { user with userData = { user.userData with exchangeUserData = { user.userData.exchangeUserData with cmeData = { user.userData.exchangeUserData.cmeData with maxOrderRatePerConnection = morpc }}}}
|
||||
| MiscTags mt -> { user with userData = { user.userData with exchangeUserData = { user.userData.exchangeUserData with cmeData = { user.userData.exchangeUserData.cmeData with miscTags = mapMiscTags mt }}}}
|
||||
| MiscTags _ ->
|
||||
// pending revamp of map edit control
|
||||
user
|
||||
| CBOTEntitlement ent -> { user with userData = { user.userData with exchangeMdEntitlementData = { user.userData.exchangeMdEntitlementData with cmeData = { user.userData.exchangeMdEntitlementData.cmeData with cbotEntitlement = { user.userData.exchangeMdEntitlementData.cmeData.cbotEntitlement with canView = ent }}}}}
|
||||
| CMEEntitlement ent -> { user with userData = { user.userData with exchangeMdEntitlementData = { user.userData.exchangeMdEntitlementData with cmeData = { user.userData.exchangeMdEntitlementData.cmeData with cmeEntitlement = { user.userData.exchangeMdEntitlementData.cmeData.cmeEntitlement with canView = ent }}}}}
|
||||
| NYMEXEntitlement ent -> { user with userData = { user.userData with exchangeMdEntitlementData = { user.userData.exchangeMdEntitlementData with cmeData = { user.userData.exchangeMdEntitlementData.cmeData with nymexEntitlement = { user.userData.exchangeMdEntitlementData.cmeData.nymexEntitlement with canView = ent }}}}}
|
||||
@@ -156,32 +155,21 @@ let applyUpdate (field:UserField) (user:BTSUser) =
|
||||
| COMEXEntitlement ent -> { user with userData = { user.userData with exchangeMdEntitlementData = { user.userData.exchangeMdEntitlementData with cmeData = { user.userData.exchangeMdEntitlementData.cmeData with comexEntitlement = { user.userData.exchangeMdEntitlementData.cmeData.comexEntitlement with canView = ent }}}}}
|
||||
| CMEEuropeEntitlement ent ->{ user with userData = { user.userData with exchangeMdEntitlementData = { user.userData.exchangeMdEntitlementData with cmeData = { user.userData.exchangeMdEntitlementData.cmeData with cmeEuropeEntitlement = { user.userData.exchangeMdEntitlementData.cmeData.cmeEuropeEntitlement with canView = ent }}}}}
|
||||
| AddAccount id ->
|
||||
let pairs = Reflection.objToPairs user.userData.accountPermissions.accountPermissions
|
||||
let tmpPermissions = {
|
||||
tradingPermission = {
|
||||
submitMarketOrders = true
|
||||
submitGtcOrders = false
|
||||
algoTradingPermission = {
|
||||
submitIcebergOrders = false
|
||||
submitTimeBoxOrders = false
|
||||
submitSpreaderOrders = false
|
||||
}
|
||||
}
|
||||
adminPermission = { hasPermissions = true }
|
||||
}
|
||||
let newPairs = (id, tmpPermissions) :: List.ofArray pairs
|
||||
let tempobj = Reflection.pairsToObj newPairs
|
||||
{ user with userData = { user.userData with accountPermissions = { user.userData.accountPermissions with accountPermissions = tempobj }}}
|
||||
let tmpPermissions =
|
||||
{ adminPermission = { hasPermissions = true }
|
||||
tradingPermission =
|
||||
{ submitMarketOrders = true
|
||||
submitGtcOrders = false
|
||||
algoTradingPermission =
|
||||
{ submitIcebergOrders = false
|
||||
submitTimeBoxOrders = false
|
||||
submitSpreaderOrders = false } } }
|
||||
let newAccountPermissions = JSMap.add id tmpPermissions user.userData.accountPermissions.accountPermissions
|
||||
let newUserData = { user.userData with accountPermissions = { user.userData.accountPermissions with accountPermissions = newAccountPermissions } }
|
||||
{ user with userData = newUserData }
|
||||
|
||||
| RemoveAccount id ->
|
||||
let pairs = Reflection.objToPairs user.userData.accountPermissions.accountPermissions
|
||||
let lst = List.ofArray pairs
|
||||
let newLst = List.filter (fun a ->
|
||||
let b, _ = a
|
||||
b <> id
|
||||
) lst
|
||||
|
||||
let newObj = Reflection.pairsToObj newLst
|
||||
let newObj = JSMap.remove id user.userData.accountPermissions.accountPermissions
|
||||
{ user with userData = { user.userData with accountPermissions = { user.userData.accountPermissions with accountPermissions = newObj }}}
|
||||
|
||||
let update msg (model:Users.Types.Model) : Model * Cmd<Msg> =
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module JSMap
|
||||
open Fable.Core.JsInterop
|
||||
open Fable.Core.DynamicExtensions
|
||||
open Fable.Core
|
||||
|
||||
module private Interop =
|
||||
open Fable.Core
|
||||
open Fable.Core.JsInterop
|
||||
[<Emit("Object.keys($0)")>]
|
||||
let keys _ : string[] = jsNative
|
||||
|
||||
[<Emit("Object.values($0)")>]
|
||||
let values<'a> _ : 'a[] = jsNative
|
||||
let pairs<'a> o =
|
||||
Array.zip (keys o) (values<'a> o)
|
||||
let spread<'a> (a:'a) (b:obj) : 'a = Imports.DynamicService.merge (a,b)
|
||||
|
||||
|
||||
type Key = string
|
||||
[<Erase>]
|
||||
type JSMap<'a> = | JSMap of obj
|
||||
|
||||
let ofArray<'a> (a:(Key*'a)[]) : JSMap<'a> = JSMap a
|
||||
let toArray<'a> (m:JSMap<'a>) : (Key*'a)[] =
|
||||
match m with | JSMap j -> Interop.pairs<'a> j
|
||||
|
||||
let ofList<'a> (l: (Key*'a) list) = JSMap l
|
||||
let toList m = m |> toArray |> List.ofArray
|
||||
|
||||
|
||||
let add<'a> (k:Key) (v:'a) (map:JSMap<'a>) =
|
||||
Interop.spread map (createObj [k ==> v])
|
||||
|
||||
let empty<'a> : JSMap<'a> = JSMap <| createObj []
|
||||
|
||||
let exists<'a> pred map =
|
||||
let pairs = Interop.pairs<'a> map
|
||||
Array.exists pred pairs
|
||||
|
||||
let filter<'a> pred map =
|
||||
Interop.pairs<'a> map
|
||||
|> Array.where pred
|
||||
|> ofArray
|
||||
|
||||
let find<'a> key (map:JSMap<'a>) =
|
||||
match map with
|
||||
| JSMap o ->
|
||||
o.[key] |> unbox<'a>
|
||||
|
||||
let containsKey key (map:JSMap<'a>) =
|
||||
Interop.keys map |> Array.contains key
|
||||
|
||||
let remove<'a> key (map:JSMap<'a>) =
|
||||
match map with
|
||||
| JSMap m ->
|
||||
Interop.pairs m
|
||||
|> Array.where (fun (k,_) -> k <> key)
|
||||
|> ofArray<'a>
|
||||
|
||||
let tryFind key (map:JSMap<'a>) : 'a option =
|
||||
map.[key] |> unbox
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<Compile Include="../../../../build/web/api/ServiceContext.fs" />
|
||||
<Compile Include="../../../../build/web/api/DynamicService.fs" />
|
||||
<Compile Include="Imports.fs" />
|
||||
<Compile Include="Util/JSMap.fs" />
|
||||
<Compile Include="../../../../build/web/api/fable/timestamp.fable.fs" />
|
||||
<Compile Include="../../../../build/web/api/fable/apicore.fable.fs" />
|
||||
<Compile Include="../../../../build/web/api/fable/apioptions.fable.fs" />
|
||||
|
||||
Reference in new issue
Block a user