1module Generate.JavaScript.Mode
13import qualified Data.List as List
14import qualified Data.Map as Map
15import qualified Data.Maybe as Maybe
16import qualified Data.Name as Name
18import qualified AST.Optimized as Opt
19import qualified Elm.Interface as I
20import qualified Generate.JavaScript.Name as JsName
28 = Dev Target (Maybe I.Interfaces)
29 | Prod Target ShortFieldNames
32data Target = Client | Server
35debug :: Target -> I.Interfaces -> Mode
36debug target interfaces =
37 Dev target (Just interfaces)
45prod :: Target -> Opt.Graph -> Mode
46prod target (Opt.Graph _ _ fieldCounts) =
47 Prod target (shortenFieldNames fieldCounts)
54isDebug :: Mode -> Bool
57 Dev _ mi -> Maybe.isJust mi
64isServer :: Mode -> Bool
67 Dev target _ -> isServerHelp target
68 Prod target _ -> isServerHelp target
71isServerHelp :: Target -> Bool
83 Map.Map Name.Name JsName.Name
86shortenFieldNames :: Map.Map Name.Name Int -> ShortFieldNames
87shortenFieldNames frequencies =
88 Map.foldr addToShortNames Map.empty $
89 Map.foldrWithKey addToBuckets Map.empty frequencies
92addToBuckets :: Name.Name -> Int -> Map.Map Int [Name.Name] -> Map.Map Int [Name.Name]
93addToBuckets field frequency buckets =
94 -- TODO try using an IntMap for buckets
95 Map.insertWith (++) frequency [field] buckets
98addToShortNames :: [Name.Name] -> ShortFieldNames -> ShortFieldNames
99addToShortNames fields shortNames =
100 List.foldl' addField shortNames fields
103addField :: ShortFieldNames -> Name.Name -> ShortFieldNames
104addField shortNames field =
105 let rename = JsName.fromInt (Map.size shortNames) in
106 Map.insert field rename shortNames
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list