Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
fix: fixed partial initial loading of native functions
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Apr 21, 2020
1 parent ea93387 commit 84b7335
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/Component/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ data Action
| SceneMouseDown (Vec2 Number)
| SceneMouseMove (Vec2 Number)
| SelectNode NodeId
| LoadNodes

data Query a
= Void
Expand Down Expand Up @@ -88,19 +89,22 @@ component =
, currentFunction: Nothing
, lastMousePosition: Nothing
, expression: nullExpr Nowhere
, project: loadPrelude $ emptyProject $ NodeId "firstOutput"
, project: emptyProject $ NodeId "firstOutput"
}
, render
, eval:
mkEval
$ defaultEval
{ handleAction = handleAction
, initialize = Just Compile
, initialize = Just LoadNodes
}
}
where
handleAction :: Action -> HalogenM State Action ChildSlots Void m Unit
handleAction = case _ of
LoadNodes -> do
modify_ loadPrelude
handleAction Compile
Compile -> do
{ project, expression } <- get
let
Expand Down
21 changes: 14 additions & 7 deletions src/Data/Dataflow/Native/NativeConfig.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Lunarbox.Data.Dataflow.Expression (NativeExpression)
import Lunarbox.Data.Editor.DataflowFunction (DataflowFunction(..))
import Lunarbox.Data.Editor.FunctionData (FunctionData)
import Lunarbox.Data.Editor.FunctionName (FunctionName)
import Lunarbox.Data.Editor.Project (Project, _atProjectFunction)
import Lunarbox.Data.Editor.State (State, _atFunctionData, _function)

newtype NativeConfig
= NativeConfig
Expand All @@ -17,12 +17,19 @@ newtype NativeConfig
, name :: FunctionName
}

loadNativeConfig :: NativeConfig -> Project -> Project
loadNativeConfig (NativeConfig { functionData, expression, name }) =
set (_atProjectFunction name)
$ Just
$ (NativeFunction expression)
loadNativeConfig :: NativeConfig -> State -> State
loadNativeConfig (NativeConfig { functionData, expression, name }) = loadFunction <<< loadFunctionData
where
loadFunction =
set (_function name)
$ Just
$ (NativeFunction expression)

loadFunctionData =
set (_atFunctionData name)
$ Just
$ functionData

-- I'm pretty proud of this one lol
loadNativeConfigs :: forall f. Foldable f => f (NativeConfig) -> Project -> Project
loadNativeConfigs :: forall f. Foldable f => f (NativeConfig) -> State -> State
loadNativeConfigs = flip $ foldr loadNativeConfig
4 changes: 2 additions & 2 deletions src/Data/Dataflow/Native/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Lunarbox.Data.Dataflow.Native.Prelude
import Lunarbox.Data.Dataflow.Native.ControlFlow (if')
import Lunarbox.Data.Dataflow.Native.Math (add)
import Lunarbox.Data.Dataflow.Native.NativeConfig (NativeConfig, loadNativeConfigs)
import Lunarbox.Data.Editor.Project (Project)
import Lunarbox.Data.Editor.State (State)

configs :: Array NativeConfig
configs = [ add, if' ]

loadPrelude :: Project -> Project
loadPrelude :: State -> State
loadPrelude = loadNativeConfigs configs
8 changes: 8 additions & 0 deletions src/Data/Editor/State.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module Lunarbox.Data.Editor.State
, _panelIsOpen
, _currentFunction
, _currentTab
, _functionData
, _atFunctionData
) where

import Prelude
Expand Down Expand Up @@ -83,6 +85,12 @@ _nodeData = prop (SProxy :: _ "nodeData")
_atNodeData :: FunctionName -> NodeId -> Lens' State (Maybe NodeData)
_atNodeData name id = _nodeData <<< at (Tuple name id)

_functionData :: Lens' State (Map FunctionName FunctionData)
_functionData = prop (SProxy :: _ "functionData")

_atFunctionData :: FunctionName -> Lens' State (Maybe FunctionData)
_atFunctionData name = _functionData <<< at name

_project :: Lens' State Project
_project = prop (SProxy :: _ "project")

Expand Down

0 comments on commit 84b7335

Please sign in to comment.