mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-25 02:34:36 +03:00
Add projectContext to Context
This commit is contained in:
parent
c5432d1a52
commit
38fdd59b4e
@ -1,20 +1,14 @@
|
||||
module Review.Context exposing (Context, Metadata, RequestedData, availableData, init, withMetadata)
|
||||
|
||||
--init : Rule.Context Context
|
||||
--init =
|
||||
-- Context.succeed (\metadata scope -> {})
|
||||
-- |> Context.withMetadata
|
||||
-- |> Context.withScope
|
||||
|
||||
type Context projectContext moduleContext
|
||||
= Context (AvailableData -> projectContext -> moduleContext) RequestedData
|
||||
|
||||
|
||||
type Context context
|
||||
= Context (AvailableData -> context) RequestedData
|
||||
|
||||
|
||||
init : context -> Context context
|
||||
init context =
|
||||
init : (projectContext -> moduleContext) -> Context projectContext moduleContext
|
||||
init fromProjectToModule =
|
||||
Context
|
||||
(always context)
|
||||
(always fromProjectToModule)
|
||||
(RequestedData { metadata = False })
|
||||
|
||||
|
||||
@ -28,40 +22,79 @@ type Metadata
|
||||
= Metadata
|
||||
|
||||
|
||||
withMetadata : Context (Metadata -> a) -> Context a
|
||||
withMetadata : Context Metadata (projectContext -> moduleContext) -> Context projectContext moduleContext
|
||||
withMetadata (Context fn (RequestedData requested)) =
|
||||
Context
|
||||
(\data -> fn data data.metadata)
|
||||
(RequestedData { requested | metadata = True })
|
||||
|
||||
|
||||
withInt : Context Int (projectContext -> moduleContext) -> Context projectContext moduleContext
|
||||
withInt (Context fn (RequestedData requested)) =
|
||||
Context
|
||||
(\data -> fn data data.int)
|
||||
(RequestedData { requested | metadata = True })
|
||||
|
||||
|
||||
type alias AvailableData =
|
||||
{ metadata : Metadata
|
||||
, int : Int
|
||||
}
|
||||
|
||||
|
||||
availableData : AvailableData
|
||||
availableData =
|
||||
{ metadata = Metadata
|
||||
, int = 1
|
||||
}
|
||||
|
||||
|
||||
apply : AvailableData -> Context context -> context
|
||||
apply data (Context fn _) =
|
||||
fn data
|
||||
apply : AvailableData -> projectContext -> Context projectContext moduleContext -> moduleContext
|
||||
apply data projectContext (Context fn _) =
|
||||
fn data projectContext
|
||||
|
||||
|
||||
requestedData : AvailableData -> Context context -> context
|
||||
requestedData data (Context fn _) =
|
||||
fn data
|
||||
requestedData : Context projectContext moduleContext -> RequestedData
|
||||
requestedData (Context _ requested) =
|
||||
requested
|
||||
|
||||
|
||||
test1 : Context Int
|
||||
test1 =
|
||||
init 1
|
||||
|
||||
|
||||
test2 : Context Int
|
||||
test2 =
|
||||
init (\Metadata -> 1)
|
||||
|> withMetadata
|
||||
-- TESTING
|
||||
--test1 : Context () Int
|
||||
--test1 =
|
||||
-- init (\() -> 1)
|
||||
--
|
||||
--
|
||||
--test1Applied : Int
|
||||
--test1Applied =
|
||||
-- test1
|
||||
-- |> apply availableData ()
|
||||
-- |> Debug.log "test 1"
|
||||
--
|
||||
--
|
||||
--test2 : Context () Int
|
||||
--test2 =
|
||||
-- init (\Metadata () -> 1)
|
||||
-- |> withMetadata
|
||||
--
|
||||
--
|
||||
--test2Applied : Int
|
||||
--test2Applied =
|
||||
-- test2
|
||||
-- |> apply availableData ()
|
||||
-- |> Debug.log "test 2"
|
||||
--
|
||||
--
|
||||
--test3 : Context () Int
|
||||
--test3 =
|
||||
-- init (\Metadata int () -> 1 + int)
|
||||
-- |> withMetadata
|
||||
-- |> withInt
|
||||
--
|
||||
--
|
||||
--test3Applied : Int
|
||||
--test3Applied =
|
||||
-- test3
|
||||
-- |> apply availableData ()
|
||||
-- |> Debug.log "test 3"
|
||||
|
Loading…
Reference in New Issue
Block a user