Last active
November 16, 2018 21:49
-
-
Save ali-abrar/e4dcb0fc1faae7beac7a3521dcc427fe to your computer and use it in GitHub Desktop.
Revisions
-
ali-abrar revised this gist
Nov 16, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,6 +33,7 @@ frontend = Frontend osmd <- call newOpenSheetMusicDisplay newOpenSheetMusicDisplay [e'] a <- toJSVal $ static @"MozartTrio.musicxml" call osmdLoad osmdLoad [osmd, a] -- The code below is just here to demonstrate how one might catch a JSException. It's not expected to do anything useful. liftIO $ putStrLn "About to throw an exception:" (call osmdLoad osmdLoad [a, osmd]) `catch` (\(JSException ex) -> liftJSM $ do log <- eval @Text "(function(err) { console['log'](err); })" -
ali-abrar revised this gist
Nov 16, 2018 . 1 changed file with 43 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} module Frontend where import Data.Text (Text) import qualified Data.Text as T import Obelisk.Frontend import Obelisk.Route import Reflex.Dom.Core import Common.Api import Common.Route import Obelisk.Generated.Static import Language.Javascript.JSaddle import Control.Monad.IO.Class frontend :: Frontend (R FrontendRoute) frontend = Frontend { _frontend_head = do el "title" $ text "OSMD Example" elAttr "script" ("type" =: "text/javascript" <> "src" =: static @"opensheetmusicdisplay.min.js") blank , _frontend_body = prerender blank $ do e <- fst <$> el' "div" blank newOpenSheetMusicDisplay <- liftJSM $ eval @Text "(function(e) { return new opensheetmusicdisplay['OpenSheetMusicDisplay'](e); })" osmdLoad <- liftJSM $ eval @Text "(function(osmd, xml) { osmd['load'](xml); })" pb <- getPostBuild osmd <- performEvent $ ffor pb $ \_ -> liftJSM $ do e' <- toJSVal $ _element_raw e osmd <- call newOpenSheetMusicDisplay newOpenSheetMusicDisplay [e'] a <- toJSVal $ static @"MozartTrio.musicxml" call osmdLoad osmdLoad [osmd, a] liftIO $ putStrLn "About to throw an exception:" (call osmdLoad osmdLoad [a, osmd]) `catch` (\(JSException ex) -> liftJSM $ do log <- eval @Text "(function(err) { console['log'](err); })" call log log [ex]) liftIO $ putStrLn "If you're reading this, the exception was caught." return osmd return () } -
ali-abrar created this gist
Nov 16, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} module Frontend where import Data.Text (Text) import qualified Data.Text as T import Obelisk.Frontend import Obelisk.Route import Reflex.Dom.Core import Common.Api import Common.Route import Obelisk.Generated.Static import Language.Javascript.JSaddle -- Built with Obelisk (https://github.com/obsidiansystems/obelisk) -- You should be able to run 'ob init' and then replace the Frontend.hs file with this file frontend :: Frontend (R FrontendRoute) frontend = Frontend { _frontend_head = do el "title" $ text "OSMD Example" -- JS from https://github.com/opensheetmusicdisplay/RawJavascript-usage-example elAttr "script" ("type" =: "text/javascript" <> "src" =: static @"opensheetmusicdisplay.min.js") blank , _frontend_body = prerender blank $ do e <- fst <$> el' "div" blank newOpenSheetMusicDisplay <- liftJSM $ eval @Text "(function(e) { return new opensheetmusicdisplay['OpenSheetMusicDisplay'](e); })" osmdLoad <- liftJSM $ eval @Text "(function(osmd, xml) { osmd['load'](xml); })" pb <- getPostBuild osmd <- performEvent $ ffor pb $ \_ -> liftJSM $ do e' <- toJSVal $ _element_raw e osmd <- call newOpenSheetMusicDisplay newOpenSheetMusicDisplay [e'] -- Music xml from https://www.musicxml.com/music-in-musicxml/example-set/ a <- toJSVal $ static @"MozartTrio.musicxml" call osmdLoad osmdLoad [osmd, a] return osmd return () }