1module Generate.JavaScript.Mode
12import qualified Data.List as List
13import qualified Data.Map as Map
15import qualified AST.Optimized as Opt
16import qualified Elm.Interface as I
17import qualified Elm.Name as N
18import qualified Generate.JavaScript.Name as Name
26 = Dev Target (Maybe I.Interfaces)
27 | Prod Target ShortFieldNames
30data Target = Client | Server
33debug :: Target -> I.Interfaces -> Mode
34debug target interfaces =
35 Dev target (Just interfaces)
43prod :: Target -> Opt.Graph -> Mode
44prod target (Opt.Graph _ _ fieldCounts) =
45 Prod target (shortenFieldNames fieldCounts)
52isServer :: Mode -> Bool
55 Dev target _ -> isServerHelp target
56 Prod target _ -> isServerHelp target
59isServerHelp :: Target -> Bool
71 Map.Map N.Name Name.Name
74shortenFieldNames :: Map.Map N.Name Int -> ShortFieldNames
75shortenFieldNames frequencies =
76 Map.foldr addToShortNames Map.empty $
77 Map.foldrWithKey addToBuckets Map.empty frequencies
80addToBuckets :: N.Name -> Int -> Map.Map Int [N.Name] -> Map.Map Int [N.Name]
81addToBuckets field frequency buckets =
82 -- TODO try using an IntMap for buckets
83 Map.insertWith (++) frequency [field] buckets
86addToShortNames :: [N.Name] -> ShortFieldNames -> ShortFieldNames
87addToShortNames fields shortNames =
88 List.foldl' addField shortNames fields
91addField :: ShortFieldNames -> N.Name -> ShortFieldNames
92addField shortNames field =
93 let rename = Name.fromInt (Map.size shortNames) in
94 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