Commit 4e609023 authored by Bas Lijnse's avatar Bas Lijnse

Merge branch 'interactLocalState' into 'master'

remove local state of interact tasks; use value derived from editor state

See merge request !366
parents 8886a576 0048b28e
Pipeline #35349 passed with stage
in 7 minutes and 22 seconds
......@@ -58,18 +58,34 @@ 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
evalInteractInit sds handlers editor writefun r _ evalOpts iworld
//Get initial value
# mode = handlers.onInit r
# v = case mode of
Enter = Nothing
Update x = Just x
View x = Just x
= evalInteract r v Nothing (mode=:View _) sds handlers editor writefun ResetEvent evalOpts iworld
= evalInteractInitWithValue r v (mode =: View _) sds handlers editor writefun evalOpts iworld
evalInteractInitWithValue r v mode sds handlers editor writefun evalOpts=:{TaskEvalOpts|taskId, lastEval} iworld
# resetMode = case (mode, v) of
(True, Just v) = View v
(True, _) = abort "view mode without value\n"
(_, Nothing) = Enter
(_, Just v) = Update v
= case withVSt taskId (editor.Editor.genUI 'DM'.newMap [] resetMode) iworld of
(Error e, iworld) = (ExceptionResult (exception e), iworld)
(Ok (UI type attr items, st), iworld)
# change = ReplaceUI (UI type (addClassAttr "interact" attr) items)
= (ValueResult
(maybe NoValue (\v->Value (r,v) False) v)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract r (Just st) mode sds handlers editor writefun))
, iworld)
evalInteract ::
r
(Maybe v)
(Maybe EditState)
Bool
(sds () r w)
......@@ -90,9 +106,9 @@ evalInteract ::
*IWorld
-> *(TaskResult (r,v),*IWorld)
| iTask r & iTask v & TC r & TC w & Registrable sds
evalInteract _ _ _ _ _ _ _ _ DestroyEvent {TaskEvalOpts|taskId} iworld
evalInteract _ _ _ _ _ _ _ DestroyEvent {TaskEvalOpts|taskId} iworld
= (DestroyedResult, 'SDS'.clearTaskSDSRegistrations ('DS'.singleton taskId) iworld)
evalInteract r v mst mode sds handlers editor writefun event=:(EditEvent eTaskId name edit) evalOpts=:{taskId,lastEval} iworld
evalInteract r 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
......@@ -112,7 +128,7 @@ evalInteract r v mst mode sds handlers editor writefun event=:(EditEvent eTaskId
(Value (r,nv) False)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract r (Just nv) (Just st) mode sds handlers editor writefun))
(Task (evalInteract r (Just st) mode sds handlers editor writefun))
, iworld))
event evalOpts iworld
//There is no update function
......@@ -121,37 +137,23 @@ evalInteract r v mst mode sds handlers editor writefun event=:(EditEvent eTaskId
(Value (r,nv) False)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract r (Just nv) (Just st) mode sds handlers editor writefun))
(Task (evalInteract r (Just st) mode sds handlers editor writefun))
, iworld)
Nothing
= (ValueResult
NoValue
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract r Nothing (Just st) mode sds handlers editor writefun))
(Task (evalInteract r (Just st) mode sds handlers editor writefun))
, iworld)
Error e = (ExceptionResult (exception e), iworld)
evalInteract r 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"
(_, Nothing) = Enter
(_, Just v) = Update v
= case withVSt taskId (editor.Editor.genUI 'DM'.newMap [] resetMode) iworld of
(Error e, iworld) = (ExceptionResult (exception e), iworld)
(Ok (UI type attr items, st), iworld)
# change = ReplaceUI (UI type (addClassAttr "interact" attr) items)
# mbv = editor.Editor.valueFromState st
# v = maybe v Just mbv
= (ValueResult
(maybe NoValue (\v->Value (r,v) False) v)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract r v (Just st) mode sds handlers editor writefun))
, iworld)
evalInteract r v mst mode sds handlers editor writefun event=:(RefreshEvent taskIds _) evalOpts=:{taskId,lastEval} iworld
evalInteract r mst mode sds handlers editor writefun ResetEvent evalOpts iworld
# v = maybe Nothing editor.Editor.valueFromState mst
= evalInteractInitWithValue r v mode sds handlers editor writefun evalOpts iworld
evalInteract r mst mode sds handlers editor writefun event=:(RefreshEvent taskIds _) evalOpts=:{taskId,lastEval} iworld
| isNothing mst = (ExceptionResult (exception "corrupt editor state"), iworld)
# st = fromJust mst
# v = editor.Editor.valueFromState st
| 'DS'.member taskId taskIds
= readRegisterCompletely sds (maybe NoValue (\v->Value (r,v) False) v) (\e->mkUIIfReset e (asyncSDSLoaderUI Read))
(\r event evalOpts iworld
......@@ -165,24 +167,25 @@ evalInteract r 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 r v (Just st) mode sds handlers editor writefun)
(\_->evalInteract r (Just st) mode sds handlers editor writefun)
event evalOpts iworld
Nothing
= (ValueResult
(maybe NoValue (\v -> Value (r,v) False) v)
(mkTaskEvalInfo lastEval)
change
(Task (evalInteract r v (Just st) mode sds handlers editor writefun))
(Task (evalInteract r (Just st) mode sds handlers editor writefun))
, iworld)
)
event evalOpts iworld
evalInteract r v mst mode sds handlers editor writefun event {lastEval} iworld
evalInteract r mst mode sds handlers editor writefun event {lastEval} iworld
# v = maybe Nothing editor.Editor.valueFromState mst
//An event for a sibling?
= (ValueResult
(maybe NoValue (\v->Value (r,v) False) v)
(mkTaskEvalInfo lastEval)
NoChange
(Task (evalInteract r v mst mode sds handlers editor writefun))
(Task (evalInteract r mst mode sds handlers editor writefun))
, iworld)
uniqueMode :: (EditMode a) -> *(EditMode a)
......
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