Add a way to "load" a cache hierarchy in from a model.
This commit is contained in:
		
							parent
							
								
									a3d6a1440f
								
							
						
					
					
						commit
						99a7be27a9
					
				@ -1,11 +1,14 @@
 | 
				
			|||||||
module CacheSim.Model exposing (..)
 | 
					module CacheSim.Model exposing (..)
 | 
				
			||||||
import CacheSim.Raw exposing (..)
 | 
					import CacheSim.Raw exposing (..)
 | 
				
			||||||
 | 
					import CacheSim.Hierarchy exposing (..)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type alias Model =
 | 
					type alias Model =
 | 
				
			||||||
    { rawHierarchy : RawCacheModelHierarchy
 | 
					    { rawHierarchy : RawCacheModelHierarchy
 | 
				
			||||||
 | 
					    , hierarchy : Maybe CacheHierarchy
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
type alias Flags = ()
 | 
					type alias Flags = ()
 | 
				
			||||||
type Msg
 | 
					type Msg
 | 
				
			||||||
    = ChangeRawModel Int (RawCacheModel -> RawCacheModel)
 | 
					    = ChangeRawModel Int (RawCacheModel -> RawCacheModel)
 | 
				
			||||||
    | CreateRawModel
 | 
					    | CreateRawModel
 | 
				
			||||||
    | DeleteRawModel Int
 | 
					    | DeleteRawModel Int
 | 
				
			||||||
 | 
					    | UseHierarchy (Maybe CacheModelHierarchy)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
module CacheSim.Update exposing (..)
 | 
					module CacheSim.Update exposing (..)
 | 
				
			||||||
import CacheSim.Model exposing (..)
 | 
					import CacheSim.Model exposing (..)
 | 
				
			||||||
 | 
					import CacheSim.Hierarchy exposing (..)
 | 
				
			||||||
import CacheSim.Raw exposing (..)
 | 
					import CacheSim.Raw exposing (..)
 | 
				
			||||||
import CacheSim.IntMap exposing (..)
 | 
					import CacheSim.IntMap exposing (..)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -27,3 +28,11 @@ updateDeleteRawModel l m =
 | 
				
			|||||||
        cmd = Cmd.none
 | 
					        cmd = Cmd.none
 | 
				
			||||||
    in
 | 
					    in
 | 
				
			||||||
        (newModel, cmd)
 | 
					        (newModel, cmd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					updateUseHierarchy : Maybe CacheModelHierarchy -> Model -> (Model, Cmd Msg)
 | 
				
			||||||
 | 
					updateUseHierarchy cmh m =
 | 
				
			||||||
 | 
					    let
 | 
				
			||||||
 | 
					        newModel = { m | hierarchy = Maybe.map freshCacheHierarchy cmh }
 | 
				
			||||||
 | 
					        cmd = Cmd.none
 | 
				
			||||||
 | 
					    in
 | 
				
			||||||
 | 
					        (newModel, cmd)
 | 
				
			||||||
 | 
				
			|||||||
@ -64,7 +64,9 @@ viewRawCacheModelHierarchy rcmh =
 | 
				
			|||||||
                Err e -> viewError False e
 | 
					                Err e -> viewError False e
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        newButton = button "Add level" CreateRawModel
 | 
					        newButton = button "Add level" CreateRawModel
 | 
				
			||||||
        useButton = optionalButton isValid "Use hierarchy" CreateRawModel
 | 
					        useButton = case translationResult of
 | 
				
			||||||
 | 
					            Ok cmh -> optionalButton True "Use hierarchy" (UseHierarchy <| Just cmh)
 | 
				
			||||||
 | 
					            Err _ -> optionalButton False "Use hierarchy" (UseHierarchy Nothing)
 | 
				
			||||||
    in
 | 
					    in
 | 
				
			||||||
        div [ class "cache-model-hierarchy" ]
 | 
					        div [ class "cache-model-hierarchy" ]
 | 
				
			||||||
            [ h2 [] [ text "Cache hierarchy" ]
 | 
					            [ h2 [] [ text "Cache hierarchy" ]
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,7 @@ init f =
 | 
				
			|||||||
    let
 | 
					    let
 | 
				
			||||||
        initialModel =
 | 
					        initialModel =
 | 
				
			||||||
            { rawHierarchy = testCacheModelHierarchy
 | 
					            { rawHierarchy = testCacheModelHierarchy
 | 
				
			||||||
 | 
					            , hierarchy = Nothing
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
    in
 | 
					    in
 | 
				
			||||||
        (initialModel, Cmd.none)
 | 
					        (initialModel, Cmd.none)
 | 
				
			||||||
@ -33,6 +34,7 @@ update msg m =
 | 
				
			|||||||
        ChangeRawModel l f -> updateChangeRawModel l f m
 | 
					        ChangeRawModel l f -> updateChangeRawModel l f m
 | 
				
			||||||
        CreateRawModel -> updateCreateRawModel m
 | 
					        CreateRawModel -> updateCreateRawModel m
 | 
				
			||||||
        DeleteRawModel i -> updateDeleteRawModel i m
 | 
					        DeleteRawModel i -> updateDeleteRawModel i m
 | 
				
			||||||
 | 
					        UseHierarchy cmh -> updateUseHierarchy cmh m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
subscriptions : Model -> Sub Msg
 | 
					subscriptions : Model -> Sub Msg
 | 
				
			||||||
subscriptions m = Sub.none 
 | 
					subscriptions m = Sub.none 
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user