From 47999f89fd30ee9c21c6f3d762432cb9386f35b9 Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Thu, 31 Jul 2025 00:39:13 -0500 Subject: [PATCH 1/4] Ues `withSink`, drop `MVar` Use `withSink` as opposed to `MVar` --- src/Main.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index d9434cd..949cbfe 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -85,16 +85,14 @@ app = (component (Model mempty) updateModel viewModel) ---------------------------------------------------------------------------- -- | Update function updateModel :: Action -> Effect Model Action -updateModel (ReadFile fileReaderInput) = io $ do +updateModel (ReadFile fileReaderInput) = withSink $ \sink -> do file <- fileReaderInput ! ("files" :: String) !! 0 reader <- J.new (J.jsg ("FileReader" :: String)) ([] :: [JSVal]) - mvar <- liftIO newEmptyMVar (reader <# ("onload" :: String)) =<< do M.asyncCallback $ do result <- J.fromJSValUnchecked =<< reader ! ("result" :: String) - liftIO (putMVar mvar result) + sink (SetContent result) void $ reader # ("readAsText" :: String) $ [file] - SetContent <$> liftIO (readMVar mvar) updateModel (SetContent c) = info .= c updateModel (ClickInput button) = io_ $ do fileReader <- button ! ("nextSibling" :: MisoString) -- dmj: gets hidden input From be8493f3ef1a250b50b77dac6595fed6fce1d35a Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Thu, 31 Jul 2025 00:41:12 -0500 Subject: [PATCH 2/4] Update main.yml `pull_request` --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01eeceb..006a328 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,7 @@ name: Build and deploy on: push: branches: main + pull_request: permissions: contents: read From 89c51a5e35399f18877750274929377eb354eff1 Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Thu, 31 Jul 2025 00:46:56 -0500 Subject: [PATCH 3/4] Use `MisoString` Uses `MisoString` --- src/Main.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 949cbfe..9a1e945 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -86,17 +86,17 @@ app = (component (Model mempty) updateModel viewModel) -- | Update function updateModel :: Action -> Effect Model Action updateModel (ReadFile fileReaderInput) = withSink $ \sink -> do - file <- fileReaderInput ! ("files" :: String) !! 0 - reader <- J.new (J.jsg ("FileReader" :: String)) ([] :: [JSVal]) - (reader <# ("onload" :: String)) =<< do + file <- fileReaderInput ! ("files" :: MisoString) !! 0 + reader <- J.new (J.jsg ("FileReader" :: MisoString)) ([] :: [JSVal]) + (reader <# ("onload" :: MisoString)) =<< do M.asyncCallback $ do - result <- J.fromJSValUnchecked =<< reader ! ("result" :: String) + result <- J.fromJSValUnchecked =<< reader ! ("result" :: MisoString) sink (SetContent result) - void $ reader # ("readAsText" :: String) $ [file] + void $ reader # ("readAsText" :: MisoString) $ [file] updateModel (SetContent c) = info .= c updateModel (ClickInput button) = io_ $ do fileReader <- button ! ("nextSibling" :: MisoString) -- dmj: gets hidden input - void $ fileReader # ("click" :: String) $ ([] :: [JSVal]) + void $ fileReader # ("click" :: MisoString) $ ([] :: [JSVal]) ---------------------------------------------------------------------------- -- | View function viewModel :: Model -> View Action From df92594df4b09109f12e0228265ebc1a541efea6 Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Thu, 31 Jul 2025 01:07:01 -0500 Subject: [PATCH 4/4] Update Main.hs --- src/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.hs b/src/Main.hs index 9a1e945..6cea4f3 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -85,7 +85,7 @@ app = (component (Model mempty) updateModel viewModel) ---------------------------------------------------------------------------- -- | Update function updateModel :: Action -> Effect Model Action -updateModel (ReadFile fileReaderInput) = withSink $ \sink -> do +updateModel (ReadFile fileReaderInput) = M.withSink $ \sink -> do file <- fileReaderInput ! ("files" :: MisoString) !! 0 reader <- J.new (J.jsg ("FileReader" :: MisoString)) ([] :: [JSVal]) (reader <# ("onload" :: MisoString)) =<< do