Skip to content

Commit

Permalink
rename blockly types
Browse files Browse the repository at this point in the history
  • Loading branch information
shmish111 committed Oct 26, 2020
1 parent 15135b8 commit 6c044dd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
34 changes: 17 additions & 17 deletions marlowe-playground-client/src/Halogen/ActusBlockly.purs
Expand Up @@ -31,26 +31,26 @@ foreign import sendContractToShiny ::
String ->
Effect Unit

type BlocklyState
type State
= { actusBlocklyState :: Maybe BT.BlocklyState
, generator :: Maybe Generator
, errorMessage :: Maybe String
, showShiny :: Boolean
}

_actusBlocklyState :: Lens' BlocklyState (Maybe BT.BlocklyState)
_actusBlocklyState :: Lens' State (Maybe BT.BlocklyState)
_actusBlocklyState = prop (SProxy :: SProxy "actusBlocklyState")

_generator :: Lens' BlocklyState (Maybe Generator)
_generator :: Lens' State (Maybe Generator)
_generator = prop (SProxy :: SProxy "generator")

_errorMessage :: Lens' BlocklyState (Maybe String)
_errorMessage :: Lens' State (Maybe String)
_errorMessage = prop (SProxy :: SProxy "errorMessage")

_showShiny :: Lens' BlocklyState Boolean
_showShiny :: Lens' State Boolean
_showShiny = prop (SProxy :: SProxy "showShiny")

data BlocklyQuery a
data Query a
= Resize a
| SetError String a
| GetWorkspace (XML -> a)
Expand All @@ -60,19 +60,19 @@ data ContractFlavour
= FS
| F

data BlocklyAction
data Action
= Inject String (Array BlockDefinition)
| GetTerms ContractFlavour
| RunAnalysis

data BlocklyMessage
data Message
= Initialized
| CurrentTerms ContractFlavour String

type DSL m a
= HalogenM BlocklyState BlocklyAction () BlocklyMessage m a
= HalogenM State Action () Message m a

blockly :: forall m. MonadEffect m => String -> Array BlockDefinition -> Component HTML BlocklyQuery Unit BlocklyMessage m
blockly :: forall m. MonadEffect m => String -> Array BlockDefinition -> Component HTML Query Unit Message m
blockly rootBlockName blockDefinitions =
mkComponent
{ initialState: const { actusBlocklyState: Nothing, generator: Nothing, errorMessage: Just "(Labs is an experimental feature)", showShiny: false }
Expand All @@ -87,7 +87,7 @@ blockly rootBlockName blockDefinitions =
}
}

handleQuery :: forall m a. MonadEffect m => BlocklyQuery a -> DSL m (Maybe a)
handleQuery :: forall m a. MonadEffect m => Query a -> DSL m (Maybe a)
handleQuery (Resize next) = do
mState <- use _actusBlocklyState
case mState of
Expand Down Expand Up @@ -120,7 +120,7 @@ handleQuery (LoadWorkspace xml next) = do
assign _errorMessage Nothing
pure $ Just next

handleAction :: forall m. MonadEffect m => BlocklyAction -> DSL m Unit
handleAction :: forall m. MonadEffect m => Action -> DSL m Unit
handleAction (Inject rootBlockName blockDefinitions) = do
blocklyState <- liftEffect $ Blockly.createBlocklyInstance rootBlockName (ElementId "actusBlocklyWorkspace") (ElementId "actusBlocklyToolbox")
let
Expand Down Expand Up @@ -182,7 +182,7 @@ handleAction RunAnalysis = do
blocklyRef :: RefLabel
blocklyRef = RefLabel "blockly"

render :: forall p. BlocklyState -> HTML p BlocklyAction
render :: forall p. State -> HTML p Action
render state =
div []
[ section [ classes [ panelSubHeader, aHorizontal ] ]
Expand All @@ -206,7 +206,7 @@ render state =

shiny ::
forall p.
BlocklyState -> HTML p BlocklyAction
State -> HTML p Action
shiny state =
aside [ classes ([ sidebarComposer, expanded false ] <> if state.showShiny then [] else [ hide ]) ]
[ div [ attr (AttrName "style") "height: 100%;" ]
Expand All @@ -220,22 +220,22 @@ shiny state =
]
]

toCodeButton :: forall p. String -> HTML p BlocklyAction
toCodeButton :: forall p. String -> HTML p Action
toCodeButton key =
button
[ onClick $ const $ Just $ GetTerms FS
]
[ text key ]

toStaticCodeButton :: forall p. String -> HTML p BlocklyAction
toStaticCodeButton :: forall p. String -> HTML p Action
toStaticCodeButton key =
button
[ onClick $ const $ Just $ GetTerms F
, classes ([ alignedButtonInTheMiddle ])
]
[ text key ]

runAnalysis :: forall p. HTML p BlocklyAction
runAnalysis :: forall p. HTML p Action
runAnalysis =
button
[ onClick $ const $ Just $ RunAnalysis
Expand Down
30 changes: 15 additions & 15 deletions marlowe-playground-client/src/Halogen/Blockly.purs
Expand Up @@ -28,44 +28,44 @@ import Text.Extra as Text
import Text.Pretty (pretty)
import Type.Proxy (Proxy(..))

type BlocklyState
type State
= { blocklyState :: Maybe BT.BlocklyState
, generator :: Maybe Generator
, errorMessage :: Maybe String
}

_blocklyState :: Lens' BlocklyState (Maybe BT.BlocklyState)
_blocklyState :: Lens' State (Maybe BT.BlocklyState)
_blocklyState = prop (SProxy :: SProxy "blocklyState")

_generator :: Lens' BlocklyState (Maybe Generator)
_generator :: Lens' State (Maybe Generator)
_generator = prop (SProxy :: SProxy "generator")

_errorMessage :: Lens' BlocklyState (Maybe String)
_errorMessage :: Lens' State (Maybe String)
_errorMessage = prop (SProxy :: SProxy "errorMessage")

emptyState :: BlocklyState
emptyState :: State
emptyState = { blocklyState: Nothing, generator: Nothing, errorMessage: Nothing }

data BlocklyQuery a
data Query a
= Resize a
| SetCode String a
| SetError String a
| GetWorkspace (XML -> a)
| LoadWorkspace XML a
| GetCodeQuery a

data BlocklyAction
data Action
= Inject String (Array BlockDefinition)
| SetData Unit
| GetCode

data BlocklyMessage
data Message
= CurrentCode String

type DSL slots m a
= HalogenM BlocklyState BlocklyAction slots BlocklyMessage m a
= HalogenM State Action slots Message m a

blockly :: forall m. MonadEffect m => String -> Array BlockDefinition -> Component HTML BlocklyQuery Unit BlocklyMessage m
blockly :: forall m. MonadEffect m => String -> Array BlockDefinition -> Component HTML Query Unit Message m
blockly rootBlockName blockDefinitions =
mkComponent
{ initialState: const emptyState
Expand All @@ -80,7 +80,7 @@ blockly rootBlockName blockDefinitions =
}
}

handleQuery :: forall slots m a. MonadEffect m => BlocklyQuery a -> DSL slots m (Maybe a)
handleQuery :: forall slots m a. MonadEffect m => Query a -> DSL slots m (Maybe a)
handleQuery (Resize next) = do
mState <- use _blocklyState
case mState of
Expand Down Expand Up @@ -147,7 +147,7 @@ handleQuery (GetCodeQuery next) = do
where
unexpected s = "An unexpected error has occurred, please raise a support issue at https://github.com/input-output-hk/plutus/issues/new: " <> s

handleAction :: forall m slots. MonadEffect m => BlocklyAction -> DSL slots m Unit
handleAction :: forall m slots. MonadEffect m => Action -> DSL slots m Unit
handleAction (Inject rootBlockName blockDefinitions) = do
blocklyState <- liftEffect $ Blockly.createBlocklyInstance rootBlockName (ElementId "blocklyWorkspace") (ElementId "blocklyToolbox")
let
Expand Down Expand Up @@ -189,7 +189,7 @@ handleAction GetCode = do
blocklyRef :: RefLabel
blocklyRef = RefLabel "blockly"

render :: forall p. BlocklyState -> HTML p BlocklyAction
render :: forall p. State -> HTML p Action
render state =
div []
[ div
Expand All @@ -200,13 +200,13 @@ render state =
[ errorMessage state.errorMessage ]
]

otherActions :: forall p. BlocklyState -> HTML p BlocklyAction
otherActions :: forall p. State -> HTML p Action
otherActions state =
div []
[ toCodeButton "Send To Simulator"
]

toCodeButton :: forall p. String -> HTML p BlocklyAction
toCodeButton :: forall p. String -> HTML p Action
toCodeButton key =
button
[ onClick $ const $ Just GetCode
Expand Down
2 changes: 1 addition & 1 deletion marlowe-playground-client/src/MainFrame/State.purs
Expand Up @@ -27,7 +27,7 @@ import Halogen (Component, get, liftEffect, query, subscribe, subscribe')
import Halogen as H
import Halogen.ActusBlockly as ActusBlockly
import Halogen.Analytics (handleActionWithAnalyticsTracking)
import Halogen.Blockly (BlocklyMessage(..))
import Halogen.Blockly (Message(..))
import Halogen.Blockly as Blockly
import Halogen.Extra (mapSubmodule)
import Halogen.HTML (HTML)
Expand Down
12 changes: 6 additions & 6 deletions marlowe-playground-client/src/MainFrame/Types.purs
Expand Up @@ -18,7 +18,7 @@ import Gists (GistAction)
import Halogen (ClassName)
import Halogen as H
import Halogen.ActusBlockly as AB
import Halogen.Blockly (BlocklyMessage, BlocklyQuery)
import Halogen.Blockly as Blockly
import Halogen.Classes (activeClass)
import Halogen.Monaco (KeyBindings)
import Halogen.Monaco as Monaco
Expand Down Expand Up @@ -70,8 +70,8 @@ data Action
| SendResultJSToSimulator
| LoadJSScript String
-- blockly
| HandleBlocklyMessage BlocklyMessage
| HandleActusBlocklyMessage AB.BlocklyMessage
| HandleBlocklyMessage Blockly.Message
| HandleActusBlocklyMessage AB.Message
-- Wallet Actions
| HandleWalletMessage Wallet.Message
| ProjectsAction Projects.Action
Expand Down Expand Up @@ -135,9 +135,9 @@ instance showView :: Show View where
type ChildSlots
= ( haskellEditorSlot :: H.Slot Monaco.Query Monaco.Message Unit
, jsEditorSlot :: H.Slot Monaco.Query Monaco.Message Unit
, blocklySlot :: H.Slot BlocklyQuery BlocklyMessage Unit
, actusBlocklySlot :: H.Slot AB.BlocklyQuery AB.BlocklyMessage Unit
, simulationSlot :: H.Slot Simulation.Query BlocklyMessage Unit
, blocklySlot :: H.Slot Blockly.Query Blockly.Message Unit
, actusBlocklySlot :: H.Slot AB.Query AB.Message Unit
, simulationSlot :: H.Slot Simulation.Query Blockly.Message Unit
, marloweEditorSlot :: H.Slot Monaco.Query Monaco.Message Unit
, walletSlot :: H.Slot Wallet.Query Wallet.Message Unit
)
Expand Down
2 changes: 1 addition & 1 deletion marlowe-playground-client/src/Simulation.purs
Expand Up @@ -9,7 +9,7 @@ import Data.BigInteger (BigInteger, fromString, fromInt)
import Data.Either (Either(..))
import Data.Enum (toEnum, upFromIncluding)
import Data.HeytingAlgebra (not, (&&))
import Data.Lens (_Just, assign, has, hasn't, modifying, nearly, only, over, preview, to, use, view, (^.))
import Data.Lens (_Just, assign, has, modifying, only, over, preview, to, use, view, (^.))
import Data.Lens.Index (ix)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.NonEmptyList (_Head)
Expand Down

0 comments on commit 6c044dd

Please sign in to comment.