I'm building a simple video player component using purescript-halogen
. The component is supposed to show a blank div with only an input button for the user to select a local file which will then act as a source URL for the video element.
I completed a working model in plain javascript and wanted to port it to purescript/halogen. I got the purescript version to compile but the web console gives me an error message Uncaught TypeError: component.initialState is not a function
and points me to this MDN reference.
This would suggest an issue with how I defined my initialState function but it's fairly standard:
component :: forall q i o m. MonadAff m => H.Component q i o m
component =
H.mkComponent
{ initialState
, render
, eval: H.mkEval $ H.defaultEval { handleAction = handleAction }
}
type State =
{ videoUrl :: Maybe String }
initialState :: forall i. i -> State
initialState _ =
{ videoUrl : Nothing
}
Is it possible that the function is called at the wrong time during its lifecycle, hence making it undefined?
The code for the component is hosted on this Github gist. And I've been following this Github issue as reference.
My package.json
:
"private": true,
"devDependencies": {
"parcel": "1.12.3",
"purescript": "^0.14.0",
"spago": "^0.19.1"
},
"scripts": {
"build": "spago build",
"test": "spago test",
"serve": "parcel dev/index.html --open",
"build-prod": "mkdir -p prod && cp dev/index.html prod/ && rm -rf dist && spago bundle-app --to prod/index.js && parcel build prod/index.html"
},
"dependencies": {
"node": "^15.12.0"
}
}
I compiled using purescript v0.14.0
, spago v0.20.0
, node v16.3.0
and tested on Firefox v89.0
in Ubuntu 20.04.2 LTS
.