1module Generate.JavaScript.Mode
13import qualified Data.List as List
14import qualified Data.Map as Map
15import qualified Data.Maybe as Maybe
17import qualified AST.Optimized as Opt
18import qualified Elm.Interface as I
19import qualified Elm.Name as N
20import qualified Generate.JavaScript.Name as Name
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 N.Name Name.Name
86shortenFieldNames :: Map.Map N.Name Int -> ShortFieldNames
87shortenFieldNames frequencies =
88 Map.foldr addToShortNames Map.empty $
89 Map.foldrWithKey addToBuckets Map.empty frequencies
92addToBuckets :: N.Name -> Int -> Map.Map Int [N.Name] -> Map.Map Int [N.Name]
93addToBuckets field frequency buckets =
94 -- TODO try using an IntMap for buckets
95 Map.insertWith (++) frequency [field] buckets
98addToShortNames :: [N.Name] -> ShortFieldNames -> ShortFieldNames
99addToShortNames fields shortNames =
100 List.foldl' addField shortNames fields
103addField :: ShortFieldNames -> N.Name -> ShortFieldNames
104addField shortNames field =
105 let rename = Name.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