<commit_before>{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo #-}
#ifdef ghcjs_HOST_OS
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE JavaScriptFFI #-}
#endif
module Reflex.Dom.WebSocket.Query (runQuery, runWebSocketQuery) where

import Data.Default
import Control.Monad.Fix
import qualified Data.ByteString.Lazy as LBS
import Data.Text (Text)
import Data.Text.Encoding
import Data.Aeson
import Reflex
import Reflex.Dom.WebSocket
import Foreign.JavaScript.TH
import Data.Maybe
import Data.JSString.Text
import Language.Javascript.JSaddle.Types (MonadJSM)

runWebSocketQuery :: (MonadJSM m, MonadJSM (Performable m), HasJSContext m, PostBuild t m, TriggerEvent t m, PerformEvent t m, MonadHold t m, Reflex t, ToJSON q, MonadFix m, Query q, FromJSON (QueryResult q), Additive q, Group q, Eq q)
         => Text
         -> QueryT t q m a
         -> m a
runWebSocketQuery url app = do
  rec ws <- textWebSocket url $ def { _webSocketConfig_send = pure . decodeUtf8 . LBS.toStrict . encode <$> reqE }
      let notifications = fromMaybe mempty . jsonDecode . textToJSString <$> _webSocket_recv ws
      (a, reqE) <- runQuery notifications app
  return a

runQuery :: (MonadHold t m, PostBuild t m, MonadFix m, Query q, Additive q, Group q, Eq q)
         => Event t (QueryResult q)
         -> QueryT t q m a
         -> m (a, Event t q)
runQuery notifications app = do
  postBuild <- getPostBuild
  rec (a, requestPatch) <- runQueryT app e
      requestUniq <- holdUniqDyn $ incrementalToDynamic requestPatch
      e <- fromNotifications requestUniq notifications
  let request = leftmost<commit_msg>Use new jsonDecode location and remove unused pragmas<commit_after>{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo #-}
module Reflex.Dom.WebSocket.Query (runQuery, runWebSocketQuery) where

import Data.Default
import Control.Monad.Fix
import qualified Data.ByteString.Lazy as LBS
import Data.Text (Text)
import Data.Text.Encoding
import Data.Aeson
import Reflex
import Reflex.Dom.WebSocket
import Reflex.Dom.WebSocket.Internal
import Foreign.JavaScript.TH
import Data.Maybe
import Data.JSString.Text
import Language.Javascript.JSaddle.Types (MonadJSM)

runWebSocketQuery :: (MonadJSM m, MonadJSM (Performable m), HasJSContext m, PostBuild t m, TriggerEvent t m, PerformEvent t m, MonadHold t m, Reflex t, ToJSON q, MonadFix m, Query q, FromJSON (QueryResult q), Additive q, Group q, Eq q)
         => Text
         -> QueryT t q m a
         -> m a
runWebSocketQuery url app = do
  rec ws <- textWebSocket url $ def { _webSocketConfig_send = pure . decodeUtf8 . LBS.toStrict . encode <$> reqE }
      let notifications = fromMaybe mempty . jsonDecode . textToJSString <$> _webSocket_recv ws
      (a, reqE) <- runQuery notifications app
  return a

runQuery :: (MonadHold t m, PostBuild t m, MonadFix m, Query q, Additive q, Group q, Eq q)
         => Event t (QueryResult q)
         -> QueryT t q m a
         -> m (a, Event t q)
runQuery notifications app = do
  postBuild <- getPostBuild
  rec (a, requestPatch) <- runQueryT app e
      requestUniq <- holdUniqDyn $ incrementalToDynamic requestPatch
      e <- fromNotifications requestUniq notifications
  let request = leftmost
{'fraction_non_alphanumeric': 0.09175691937424789, 'fraction_numerical': 0.0006016847172081829, 'mean_word_length': 3.63091922005571, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '972414', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1070, 'n_words': 359}