@@ -22,6 +22,10 @@
22{-# LANGUAGE TypeFamilies #-}
22{-# LANGUAGE TypeFamilies #-}
23{-# LANGUAGE TypeOperators #-}
23{-# LANGUAGE TypeOperators #-}
24{-# LANGUAGE UndecidableInstances #-}
24{-# LANGUAGE UndecidableInstances #-}
26+{-# LANGUAGE ForeignFunctionInterface #-}
27+{-# LANGUAGE JavaScriptFFI #-}
25module Reflex.Dom.Builder.Immediate
29module Reflex.Dom.Builder.Immediate
26 ( EventTriggerRef (..)
30 ( EventTriggerRef (..)
27 , ImmediateDomBuilderEnv (..)
31 , ImmediateDomBuilderEnv (..)
@@ -297,16 +301,7 @@ deleteBetweenExclusive s e = liftJSM $ do
297-- and e will not be moved
301-- and e will not be moved
298extractBetweenExclusive :: (MonadJSM m, IsNode start, IsNode end) => DOM.DocumentFragment -> start -> end -> m ()
302extractBetweenExclusive :: (MonadJSM m, IsNode start, IsNode end) => DOM.DocumentFragment -> start -> end -> m ()
299extractBetweenExclusive df s e = liftJSM $ do
303extractBetweenExclusive df s e = liftJSM $ do
300− f <- eval $ T.unlines
304+ f <- eval ("(function(df,s,e) { var x; for(;;) { x = s['nextSibling']; if(e===x) { break; }; df['appendChild'](x); } })" :: Text)
301− [ "(function(df,s,e){"
304− , " x = s.nextSibling;"
305− , " if(e===x) break;"
306− , " df.appendChild(x);"
310 void $ call f f (df, s, e)
305 void $ call f f (df, s, e)
312-- | s and e must both be children of the same node and s must precede e;
307-- | s and e must both be children of the same node and s must precede e;
@@ -318,20 +313,17 @@ deleteUpTo s e = do
318 extractUpTo df s e -- In many places in ImmediateDomBuilderT, we assume that things always have a parent; by adding them to this DocumentFragment, we maintain that invariant
313 extractUpTo df s e -- In many places in ImmediateDomBuilderT, we assume that things always have a parent; by adding them to this DocumentFragment, we maintain that invariant
320extractUpTo :: (MonadJSM m, IsNode start, IsNode end) => DOM.DocumentFragment -> start -> end -> m ()
315extractUpTo :: (MonadJSM m, IsNode start, IsNode end) => DOM.DocumentFragment -> start -> end -> m ()
317+--NOTE: Although wrapping this javascript in a function seems unnecessary, GHCJS's optimizer will break it if it is entered without that wrapping (as of 2017-09-04)
318+foreign import javascript unsafe
319+ "(function() { var x = $2; while(x !== $3) { var y = x['nextSibling']; $1['appendChild'](x); x = y; } })()"
320+ extractUpTo_ :: DOM.DocumentFragment -> DOM.Node -> DOM.Node -> IO ()
321+extractUpTo df s e = liftJSM $ extractUpTo_ df (toNode s) (toNode e)
321extractUpTo df s e = liftJSM $ do
323extractUpTo df s e = liftJSM $ do
322− f <- eval $ T.unlines
324+ f <- eval ("(function(df,s,e){ var x = s; var y; for(;;) { y = x['nextSibling']; df['appendChild'](x); if(e===y) { break; } x = y; } })" :: Text)
323− [ "(function(df,s,e){"
327− , " y = x.nextSibling;"
328− , " df.appendChild(x);"
329− , " if(e===y) break;"
334 void $ call f f (df, s, e)
325 void $ call f f (df, s, e)
336type SupportsImmediateDomBuilder t m = (Reflex t, MonadJSM m, MonadHold t m, MonadFix m, MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref JSM, MonadAdjust t m, PrimMonad m)
328type SupportsImmediateDomBuilder t m = (Reflex t, MonadJSM m, MonadHold t m, MonadFix m, MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref JSM, MonadAdjust t m, PrimMonad m)
@@ -1567,6 +1559,10 @@ instance MonadHold t m => MonadHold t (ImmediateDomBuilderT t m) where
1567 holdDyn v0 v' = lift $ holdDyn v0 v'
1559 holdDyn v0 v' = lift $ holdDyn v0 v'
1568 {-# INLINABLE holdIncremental #-}
1560 {-# INLINABLE holdIncremental #-}
1569 holdIncremental v0 v' = lift $ holdIncremental v0 v'
1561 holdIncremental v0 v' = lift $ holdIncremental v0 v'
1562+ {-# INLINABLE buildDynamic #-}
1563+ buildDynamic a0 = lift . buildDynamic a0
1564+ {-# INLINABLE headE #-}
1565+ headE = lift . headE
1571data WindowConfig t = WindowConfig -- No config options yet
1567data WindowConfig t = WindowConfig -- No config options yet