Commit 7c7d1011 authored by Bas Lijnse's avatar Bas Lijnse Committed by Steffen Michels

Removed local state from interaction handlers

parent 81874299
......@@ -67,17 +67,17 @@ accWorldOSError :: !(*World -> (MaybeOSError a, *World)) -> Task a |
:: OSException = OSException !OSError
instance toString OSException
:: InteractionHandlers l r w v =
{ onInit :: !(r -> (l, EditMode v))
, onEdit :: !(v l -> (l, Maybe (r -> w)))
, onRefresh :: !(r l (Maybe v) -> (l, Maybe v, Maybe (r -> w)))
:: InteractionHandlers r w v =
{ onInit :: !(r -> (EditMode v))
, onEdit :: !(v -> (Maybe (r -> w)))
, onRefresh :: !(r (Maybe v) -> (Maybe v, Maybe (r -> w)))
}
/**
* Core interaction task. All other interaction tasks are derived from this
* one. `interactR` is almost identical but does not update the given sds.
*/
interactRW :: !(sds () r w) (InteractionHandlers l r w v) (Editor v) -> Task v | iTask l & iTask r & iTask v & TC r & TC w & RWShared sds
interactRW :: !(sds () r w) (InteractionHandlers r w v) (Editor v) -> Task v | iTask r & iTask v & TC r & TC w & RWShared sds
//* See documentation on `interactRW`.
interactR :: (sds () r w) (InteractionHandlers l r w v) (Editor v) -> Task v | iTask l & iTask r & iTask v & TC r & TC w & Registrable sds
interactR :: (sds () r w) (InteractionHandlers r w v) (Editor v) -> Task v | iTask r & iTask v & TC r & TC w & Registrable sds
......@@ -47,33 +47,32 @@ instance toString OSException
where
toString (OSException (_,err)) = "Error performing OS operation: " +++ err
interactRW :: !(sds () r w) (InteractionHandlers l r w v) (Editor v) -> Task v
| iTask l & iTask r & iTask v & TC r & TC w & RWShared sds
interactRW :: !(sds () r w) (InteractionHandlers r w v) (Editor v) -> Task v
| iTask r & iTask v & TC r & TC w & RWShared sds
interactRW shared handlers editor
= Task (readRegisterCompletely shared NoValue (\event->mkUIIfReset event (asyncSDSLoaderUI Read)) (evalInteractInit shared handlers editor modifyCompletely))
interactR :: (sds () r w) (InteractionHandlers l r w v) (Editor v) -> Task v
| iTask l & iTask r & iTask v & TC r & TC w & Registrable sds
interactR :: (sds () r w) (InteractionHandlers r w v) (Editor v) -> Task v
| iTask r & iTask v & TC r & TC w & Registrable sds
interactR shared handlers editor
= Task (readRegisterCompletely shared NoValue (\event->mkUIIfReset event (asyncSDSLoaderUI Read)) (evalInteractInit shared handlers editor \_ _->modifyCompletely (\()->undef) nullShare))
//This initializes the editor state and continues with the actual interact task
evalInteractInit sds handlers editor writefun r event evalOpts=:{TaskEvalOpts|taskId} iworld
//Get initial value
# (l, mode) = handlers.onInit r
# mode = handlers.onInit r
# v = case mode of
Enter = Nothing
Update x = Just x
View x = Just x
= evalInteract l v Nothing (mode=:View _) sds handlers editor writefun ResetEvent evalOpts iworld
= evalInteract v Nothing (mode=:View _) sds handlers editor writefun ResetEvent evalOpts iworld
evalInteract ::
l
(Maybe v)
(Maybe EditState)
Bool
(sds () r w)
(InteractionHandlers l r w v)
(InteractionHandlers r w v)
(Editor v)
(
(r -> w)
......@@ -89,10 +88,10 @@ evalInteract ::
TaskEvalOpts
*IWorld
-> *(TaskResult v,*IWorld)
| iTask l & iTask r & iTask v & TC r & TC w & Registrable sds
evalInteract _ _ _ _ _ _ _ _ DestroyEvent {TaskEvalOpts|taskId} iworld
| iTask r & iTask v & TC r & TC w & Registrable sds
evalInteract _ _ _ _ _ _ _ DestroyEvent {TaskEvalOpts|taskId} iworld
= (DestroyedResult, 'SDS'.clearTaskSDSRegistrations ('DS'.singleton taskId) iworld)
evalInteract l v mst mode sds handlers editor writefun event=:(EditEvent eTaskId name edit) evalOpts=:{taskId,lastEval} iworld
evalInteract v mst mode sds handlers editor writefun event=:(EditEvent eTaskId name edit) evalOpts=:{taskId,lastEval} iworld
| isNothing mst = (ExceptionResult (exception "corrupt editor state"), iworld)
| eTaskId == taskId
# (res, iworld) = withVSt taskId (editor.Editor.onEdit [] (s2dp name,edit) (fromJust mst)) iworld
......@@ -100,7 +99,7 @@ evalInteract l v mst mode sds handlers editor writefun event=:(EditEvent eTaskId
Ok (change, st)
= case editor.Editor.valueFromState st of
Just nv
# (l, mbf) = handlers.InteractionHandlers.onEdit nv l
# mbf = handlers.InteractionHandlers.onEdit nv
= case mbf of
//We have an update function
Just f = writefun f sds NoValue (\_->change)
......@@ -112,7 +111,7 @@ evalInteract l v mst mode sds handlers editor writefun event=:(EditEvent eTaskId
(Value nv False)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract l (Just nv) (Just st) mode sds handlers editor writefun))
(Task (evalInteract (Just nv) (Just st) mode sds handlers editor writefun))
, iworld))
event evalOpts iworld
//There is no update function
......@@ -121,17 +120,17 @@ evalInteract l v mst mode sds handlers editor writefun event=:(EditEvent eTaskId
(Value nv False)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract l (Just nv) (Just st) mode sds handlers editor writefun))
(Task (evalInteract (Just nv) (Just st) mode sds handlers editor writefun))
, iworld)
Nothing
= (ValueResult
NoValue
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract l Nothing (Just st) mode sds handlers editor writefun))
(Task (evalInteract Nothing (Just st) mode sds handlers editor writefun))
, iworld)
Error e = (ExceptionResult (exception e), iworld)
evalInteract l v mst mode sds handlers editor writefun ResetEvent evalOpts=:{taskId,lastEval} iworld
evalInteract v mst mode sds handlers editor writefun ResetEvent evalOpts=:{taskId,lastEval} iworld
# resetMode = case (mode, v) of
(True, Just v) = View v
(True, _) = abort "view mode without value\n"
......@@ -147,15 +146,15 @@ evalInteract l v mst mode sds handlers editor writefun ResetEvent evalOpts=:{tas
(maybe NoValue (\v->Value v False) v)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract l v (Just st) mode sds handlers editor writefun))
(Task (evalInteract v (Just st) mode sds handlers editor writefun))
, iworld)
evalInteract l v mst mode sds handlers editor writefun event=:(RefreshEvent taskIds _) evalOpts=:{taskId,lastEval} iworld
evalInteract v mst mode sds handlers editor writefun event=:(RefreshEvent taskIds _) evalOpts=:{taskId,lastEval} iworld
| isNothing mst = (ExceptionResult (exception "corrupt editor state"), iworld)
# st = fromJust mst
| 'DS'.member taskId taskIds
= readRegisterCompletely sds (maybe NoValue (\v->Value v False) v) (\e->mkUIIfReset e (asyncSDSLoaderUI Read))
(\r event evalOpts iworld
# (l, mbV, mbf) = handlers.InteractionHandlers.onRefresh r l v
# (mbV, mbf) = handlers.InteractionHandlers.onRefresh r v
# mbChange = case mbV of
Just v = withVSt taskId (editor.Editor.onRefresh [] v st) iworld
Nothing = (Ok (NoChange, st), iworld)
......@@ -165,24 +164,24 @@ evalInteract l v mst mode sds handlers editor writefun event=:(RefreshEvent task
# v = editor.Editor.valueFromState st
= case mbf of
Just f = writefun f sds NoValue (\_->change)
(\_->evalInteract l v (Just st) mode sds handlers editor writefun)
(\_->evalInteract v (Just st) mode sds handlers editor writefun)
event evalOpts iworld
Nothing
= (ValueResult
(maybe NoValue (\v -> Value v False) v)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract l v (Just st) mode sds handlers editor writefun))
(Task (evalInteract v (Just st) mode sds handlers editor writefun))
, iworld)
)
event evalOpts iworld
evalInteract l v mst mode sds handlers editor writefun event {lastEval} iworld
evalInteract v mst mode sds handlers editor writefun event {lastEval} iworld
//An event for a sibling?
= (ValueResult
(maybe NoValue (\v->Value v False) v)
(mkTaskEvalInfo lastEval)
NoChange
(Task (evalInteract l v mst mode sds handlers editor writefun))
(Task (evalInteract v mst mode sds handlers editor writefun))
, iworld)
uniqueMode :: (EditMode a) -> *(EditMode a)
......
......@@ -97,29 +97,29 @@ enterInformation options = enterInformation` (enterEditor options)
enterInformation` (EnterUsing fromf editor)
= interactRW unitShare handlers editor @ (\v -> fromf v)
where
handlers = {onInit = const ((), Enter), onEdit = \_ () -> ((), Nothing), onRefresh = \r () _ -> ((),undef,Nothing)}
handlers = {onInit = const Enter, onEdit = \_ -> Nothing, onRefresh = \r _ -> (undef,Nothing)}
viewInformation :: ![ViewOption m] !m -> Task m | iTask m
viewInformation options m = viewInformation` (viewEditor options) m
viewInformation` (ViewUsing tof editor) m
= interactR unitShare {onInit = const ((),View $ tof m), onEdit = \_ l -> (l, Nothing), onRefresh = \r l v -> (l,v,Nothing)} editor @! m
= interactR unitShare {onInit = const (View $ tof m), onEdit = \_ -> Nothing, onRefresh = \r v -> (v,Nothing)} editor @! m
updateInformation :: ![UpdateOption m] m -> Task m | iTask m
updateInformation options m = updateInformation` (updateEditor options) m
updateInformation` (UpdateUsing tof fromf editor) m
= interactRW unitShare {onInit = const ((), Update $ tof m), onEdit = \_ l -> (l, Nothing), onRefresh = \r l v -> (l,v,Nothing)}
= interactRW unitShare {onInit = const (Update $ tof m), onEdit = \_ -> Nothing, onRefresh = \r v -> (v,Nothing)}
editor @ (\v -> fromf m v)
updateSharedInformation :: ![UpdateSharedOption r w] !(sds () r w) -> Task r | iTask r & iTask w & RWShared sds
updateSharedInformation options sds = updateSharedInformation` (updateSharedEditor options) sds
updateSharedInformation` (UpdateSharedUsing tof fromf conflictf editor) sds
= interactRW sds {onInit = \r -> ((), Update $ tof r), onEdit = \v () -> ((), Just (\r -> fromf r v)), onRefresh = \r _ v -> ((),conflictf (tof r) v, Nothing)}
= interactRW sds {onInit = \r -> Update $ tof r, onEdit = \v -> Just (\r -> fromf r v), onRefresh = \r v -> (conflictf (tof r) v, Nothing)}
editor
||- watch sds //TEMPORARY: Don't use an extra task here
<<@ ApplyLayout unwrapUI
updateSharedInformation` (UpdateSharedUsingAuto tof fromf conflictf editor) sds
= interactRW sds {onInit = \r -> ((), maybe Enter Update (tof r)), onEdit = \v () -> ((), Just (\r -> fromf r v))
, onRefresh = \r _ v -> ((), maybe Nothing (\r` -> conflictf r` v) (tof r), Nothing)}
= interactRW sds {onInit = \r -> maybe Enter Update (tof r), onEdit = \v -> (Just (\r -> fromf r v))
, onRefresh = \r v -> (maybe Nothing (\r` -> conflictf r` v) (tof r), Nothing)}
editor
||- watch sds //TEMPORARY: Don't use an extra task here
<<@ ApplyLayout unwrapUI
......@@ -127,7 +127,7 @@ updateSharedInformation` (UpdateSharedUsingAuto tof fromf conflictf editor) sds
viewSharedInformation :: ![ViewOption r] !(sds () r w) -> Task r | iTask r & TC w & Registrable sds
viewSharedInformation options sds = viewSharedInformation` (viewEditor options) sds
viewSharedInformation` (ViewUsing tof editor) sds
= interactR sds {onInit = \r -> ((), View $ tof r), onEdit = \_ () -> ((), Nothing), onRefresh = \r _ _ -> ((),Just $ tof r,Nothing)} editor
= interactR sds {onInit = \r -> View $ tof r, onEdit = \_ -> Nothing, onRefresh = \r _ -> (Just $ tof r,Nothing)} editor
||- watch sds //TEMPORARY: Don't use an extra task here
<<@ ApplyLayout unwrapUI
......@@ -137,9 +137,9 @@ updateInformationWithShared` (UpdateSharedUsing tof fromf conflictf editor) sds
= withShared m
\sdsm ->
interactRW (sds |*< sdsm)
{onInit = \(r,m) -> ((), Update $ tof (r,m))
,onEdit = \v () -> ((),Just (\(r,m) -> fromf (r,m) v))
,onRefresh = \(r,m) () _ -> ((),Just $ tof (r,m), Nothing)
{onInit = \(r,m) -> (Update $ tof (r,m))
,onEdit = \v -> (Just (\(r,m) -> fromf (r,m) v))
,onRefresh = \(r,m) _ -> (Just $ tof (r,m), Nothing)
} editor
||- watch sdsm //TEMPORARY: Don't use an extra task here
<<@ ApplyLayout unwrapUI
......@@ -148,18 +148,18 @@ editSelection :: ![SelectOption c a] c [Int] -> Task [a] | iTask a
editSelection options container sel = editSelection` (selectAttributes options) (selectEditor options) container sel
editSelection` attributes (SelectUsing toView fromView editor) container sel
= interactRW unitShare
{onInit = \r -> ((), Update (toView container,sel))
,onEdit = \_ () -> ((), Nothing)
,onRefresh = \_ () v -> ((),v,Nothing)
{onInit = \r -> (Update (toView container,sel))
,onEdit = \_ -> Nothing
,onRefresh = \_ v -> (v,Nothing)
} (attributes @>> editor) @ (\(_,sel) -> fromView container sel)
editSelectionWithShared :: ![SelectOption c a] (sds () c w) (c -> [Int]) -> Task [a] | iTask c & iTask a & TC w & RWShared sds
editSelectionWithShared options sharedContainer initSel = editSelectionWithShared` (selectAttributes options) (selectEditor options) sharedContainer initSel
editSelectionWithShared` attributes (SelectUsing toView fromView editor) sharedContainer initSel
= (((interactRW sharedContainer
{onInit = \r -> ((), Update(toView r, initSel r))
,onEdit = \_ () -> ((), Nothing)
,onRefresh = \r () v -> ((),(\(_, sel) -> (toView r,sel)) <$> v,Nothing)
{onInit = \r -> Update (toView r, initSel r)
,onEdit = \_ -> Nothing
,onRefresh = \r v -> ((\(_, sel) -> (toView r,sel)) <$> v,Nothing)
} (attributes @>> editor) @ (\(_,sel) -> sel))
-&&- watch sharedContainer //TEMPORARY: Don't use an extra task here
) @ (\(sel,container) -> fromView container sel)
......@@ -169,9 +169,9 @@ editSharedSelection :: ![SelectOption c a] c (Shared sds [Int]) -> Task [a] | iT
editSharedSelection options container sharedSel = editSharedSelection` (selectAttributes options) (selectEditor options) container sharedSel
editSharedSelection` attributes (SelectUsing toView fromView editor) container sharedSel
= interactRW sharedSel
{onInit = \r -> ((), Update (toView container,r))
,onEdit = \(_,vs) () -> ((), Just (const vs))
,onRefresh = \r () v -> ((),(\(vt, _) -> (vt, r)) <$> v,Nothing)
{onInit = \r -> Update (toView container,r)
,onEdit = \(_,vs) -> Just (const vs)
,onRefresh = \r v -> ((\(vt, _) -> (vt, r)) <$> v,Nothing)
} (attributes @>> editor) @ (\(_,sel) -> fromView container sel)
editSharedSelectionWithShared :: ![SelectOption c a] (sds1 () c w) (Shared sds2 [Int]) -> Task [a] | iTask c & iTask a & TC w & RWShared sds1 & RWShared sds2
......@@ -179,9 +179,9 @@ editSharedSelectionWithShared options sharedContainer sharedSel
= editSharedSelectionWithShared` (selectAttributes options) (selectEditor options) sharedContainer sharedSel
editSharedSelectionWithShared` attributes (SelectUsing toView fromView editor) sharedContainer sharedSel
= (((interactRW (sharedContainer |*< sharedSel)
{onInit = \(rc, rs) -> ((), Update (toView rc,rs))
,onEdit = \(_, vs) () -> ((), Just (const vs))
,onRefresh = \(rc, rs) _ _ -> ((), Just (toView rc, rs), Nothing)
{onInit = \(rc, rs) -> Update (toView rc,rs)
,onEdit = \(_, vs) -> Just (const vs)
,onRefresh = \(rc, rs) _ -> (Just (toView rc, rs), Nothing)
} (attributes @>> editor) @ snd)
-&&- watch sharedContainer //TEMPORARY: Don't use an extra task here
) @ (\(sel,container) -> fromView container sel)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment