on develop help sign in
Merge branch 'develop' into dn-add-geoloc-android
commitf17d59e8e3ac16da9c8258b460318b3492985608 authorJohn Ericson <John.Ericson@Obsidian.Systems> dateThu 12 Dec 2019, 13:26 (7 years ago) parenta5e297ba579bf7
7 files changed+88−67
FAQ.md+31 default.nix−53 dep/reflex-platform/github.json+2−2 reflex-dom-core/ChangeLog.md+9 reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs+9−2 reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+1−1 release.nix+36−9
FAQ.mdnew file+31
@@ -0,0 +1,31 @@
1+# Frequently Asked Questions
2+
3+### How do I configure DOM events with flags like `preventDefault` and `stopPropagation`?
4+
5+Using `element`, a low-level DOM builder function. Its second argument, `ElementConfig`, has a `_elementConfig_eventSpec` field that can be modified using `addEventSpecFlags`. It takes a `Proxy` that specifies the `DomSpace`, an event name, and a callback which takes the event result and returns an event flag, which can enable behavior like `preventDefault` and `stopPropagation`.
6+
7+The type signature on `def` is needed because the fields of the `ElementConfig` can change the type of the `ElementConfig`. GHC can probably figure out the type of the resulting `ElementConfig`, but it doesn't know what the type of `def` was before the modifications, since it never gets used with that configuration.
8+
9+For example:
10+
11+```haskell
12+{-# LANGUAGE OverloadedStrings #-}
13+{-# LANGUAGE ScopedTypeVariables #-}
14+
15+import Control.Lens ((&), (%~), (.~))
16+import Data.Proxy
17+import Reflex.Dom
18+
19+main :: IO ()
20+main = mainWidget $ do
21+ (click, ()) <- linkPreventDefault $ text "reflex-frp"
22+ display =<< count click
23+
24+linkPreventDefault :: forall t m a. DomBuilder t m => m a -> m (Event t (), a)
25+linkPreventDefault c = do
26+ let cfg = (def :: ElementConfig EventResult t (DomBuilderSpace m))
27+ & elementConfig_initialAttributes .~ ("href" =: "https://reflex-frp.org")
28+ & elementConfig_eventSpec %~ addEventSpecFlags (Proxy :: Proxy (DomBuilderSpace m)) Click (const preventDefault)
29+ (link, a) <- element "a" cfg c
30+ return (domEvent Click link, a)
31+```
default.nixdeleted−53
@@ -1,53 +0,0 @@
1−haskellPackages: let
2− pkgs = haskellPackages.callPackage ({ pkgs }: pkgs) {};
3− inherit (pkgs) stdenv;
4− haskellLib = pkgs.haskell.lib;
5−in {
6− reflex-dom-core = let
7− inherit (haskellPackages) ghc;
8− noGcTest = stdenv.hostPlatform.system != "x86_64-linux"
9− || stdenv.hostPlatform != stdenv.buildPlatform
10− || (ghc.isGhcjs or false);
11− in haskellLib.overrideCabal
12− (haskellPackages.callCabal2nix "reflex-dom-core" ./reflex-dom-core { })
13− (drv: {
14− #TODO: Get hlint working for cross-compilation
15− doCheck = stdenv.hostPlatform == stdenv.buildPlatform && !(ghc.isGhcjs or false);
16−
17− # The headless browser run as part of the tests will exit without this
18− preBuild = ''
19− export HOME="$PWD"
20− '';
21−
22− # Show some output while running tests, so we might notice what's wrong
23− testTarget = "--show-details=streaming";
24−
25− testHaskellDepends = with haskellPackages; (drv.testHaskellDepends or []) ++ stdenv.lib.optionals (!noGcTest) [
26− temporary
27− jsaddle-warp
28− process
29− chrome-test-utils
30− ];
31−
32− testSystemDepends = with pkgs; (drv.testSystemDepends or []) ++ [
33− selenium-server-standalone which
34− ] ++ stdenv.lib.optionals (!noGcTest) [
35− chromium
36− pkgs.iproute
37− ];
38− } // stdenv.lib.optionalAttrs (!noGcTest) {
39− # The headless browser run as part of gc tests would hang/crash without this
40− preCheck = ''
41− export FONTCONFIG_PATH=${pkgs.fontconfig.out}/etc/fonts
42− '';
43− });
44− reflex-dom = haskellLib.overrideCabal
45− (haskellPackages.callCabal2nix "reflex-dom" ./reflex-dom { })
46− (drv: {
47− # Hack until https://github.com/NixOS/cabal2nix/pull/432 lands
48− libraryHaskellDepends = (drv.libraryHaskellDepends or []) ++ stdenv.lib.optionals (with stdenv.hostPlatform; isAndroid && is32bit) [
49− haskellPackages.android-activity
50− ];
51− });
52− chrome-test-utils = haskellPackages.callCabal2nix "chrome-test-utils" ./chrome-test-utils {};
53−}
dep/reflex-platform/github.json+2−2
@@ -2,6 +2,6 @@
22 "owner": "reflex-frp",
33 "repo": "reflex-platform",
44 "branch": "develop",
5− "rev": "338fc907e37d70e6469c529456f33221fb05ca1f",
6− "sha256": "08gfhpp0pkvvi1wnlpcn6wmpzdjvy5z7dy1h66gp2w8b5cx8hx5h"
5+ "rev": "e7b76dd552a10916c7d8702c11292dac4f4299ea",
6+ "sha256": "0s1183arrwldcs50qhzgnv94v24n9bgq6dfq64wp0a3q2nzyvgwh"
77}
reflex-dom-core/ChangeLog.md+9
@@ -2,6 +2,15 @@
22
33## Unreleased
44
5+* Deprecate a number of old inflexible widget helpers in `Reflex.Dom.Widget.Basic`:
6+ * `Link`
7+ * `button`
8+ * `dtdd`
9+ * `linkClass`
10+ * `link`
11+ * `tabDisplay`
12+ * `tableDynAttr`
13+
514## 0.5.2
615
716* Update to use new dependent-sum/map packages and drop dependency on `*Tag` classes (e.g., `ShowTag`).
reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs+9−2
@@ -138,6 +138,7 @@ dynComment t = do
138138display :: (PostBuild t m, DomBuilder t m, Show a) => Dynamic t a -> m ()
139139display = dynText . fmap (T.pack . show)
140140
141+{-# DEPRECATED button "Use 'elAttr'' in combination with 'domEvent' instead" #-}
141142button :: DomBuilder t m => Text -> m (Event t ())
142143button t = do
143144 (e, _) <- element "button" def $ text t
@@ -291,23 +292,25 @@ elDynHtmlAttr' elementTag attrs html = do
291292 wrapElement defaultDomEventHandler e
292293-}
293294
295+{-# DEPRECATED Link "Will be removed when 'linkClass' and 'link' are removed" #-}
294296newtype Link t
295297 = Link { _link_clicked :: Event t ()
296298 }
297299
298−-- | >>> linkClass "Click here" "link-class"
299−-- > <a class="link-class">Click here</a>
300+{-# DEPRECATED linkClass "Use 'elAttr'' in combination with 'domEvent' for just clicks. Use 'routeLink' for Obelisk navigation" #-}
300301linkClass :: DomBuilder t m => Text -> Text -> m (Link t)
301302linkClass s c = do
302303 (l,_) <- elAttr' "a" ("class" =: c) $ text s
303304 return $ Link $ domEvent Click l
304305
306+{-# DEPRECATED link "Use 'elAttr'' in combination with 'domEvent' for just clicks. Use 'routeLink' for Obelisk navigation" #-}
305307link :: DomBuilder t m => Text -> m (Link t)
306308link s = linkClass s ""
307309
308310divClass :: forall t m a. DomBuilder t m => Text -> m a -> m a
309311divClass = elClass "div"
310312
313+{-# DEPRECATED dtdd "Use an application specific widget generating function" #-}
311314dtdd :: forall t m a. DomBuilder t m => Text -> m a -> m a
312315dtdd h w = do
313316 el "dt" $ text h
@@ -316,7 +319,9 @@ dtdd h w = do
316319blank :: forall m. Monad m => m ()
317320blank = return ()
318321
322+-- TODO: Move to an example project.
319323-- | A widget to display a table with static columns and dynamic rows.
324+{-# DEPRECATED tableDynAttr "Use an application specific widget generating function" #-}
320325tableDynAttr :: forall t m r k v. (Ord k, DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m)
321326 => Text -- ^ Class applied to <table> element
322327 -> [(Text, k -> Dynamic t r -> m v)] -- ^ Columns of (header, row key -> row value -> child widget)
@@ -332,9 +337,11 @@ tableDynAttr klass cols dRows rowAttrs = elAttr "div" (Map.singleton "style" "zo
332337 dAttrs <- rowAttrs k
333338 elDynAttr' "tr" dAttrs $ mapM (\x -> el "td" $ snd x k r) cols)
334339
340+-- TODO: Move to an example project.
335341-- | A widget to construct a tabbed view that shows only one of its child widgets at a time.
336342-- Creates a header bar containing a <ul> with one <li> per child; clicking a <li> displays
337343-- the corresponding child and hides all others.
344+{-# DEPRECATED tabDisplay "Use an application specific widget generating function" #-}
338345tabDisplay :: forall t m k. (MonadFix m, DomBuilder t m, MonadHold t m, PostBuild t m, Ord k)
339346 => Text -- ^ Class applied to <ul> element
340347 -> Text -- ^ Class applied to currently active <li> element
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+1−1
@@ -287,7 +287,7 @@ regularToCheckboxViewEventType en r = case en of
287287
288288newtype CheckboxViewEventResult en = CheckboxViewEventResult { unCheckboxViewEventResult :: CheckboxViewEventResultType en }
289289
290−--TODO
290+-- | Create a view only checkbox
291291{-# INLINABLE checkboxView #-}
292292checkboxView :: forall t m. (DomBuilder t m, DomBuilderSpace m ~ GhcjsDomSpace, PostBuild t m, MonadHold t m) => Dynamic t (Map Text Text) -> Dynamic t Bool -> m (Event t Bool)
293293checkboxView dAttrs dValue = do
release.nix+36−9
@@ -17,16 +17,43 @@ let
1717 ] ++ lib.optionals (reflex-platform.iosSupport) [
1818 "ghcIosAarch64"
1919 ];
20− hsPkgs = lib.genAttrs compilers (ghc: let
21− ghc' = reflex-platform.${ghc}.override {
22− overrides = self: super: import ./. self;
23− };
24− in {
25− inherit (ghc') reflex-dom reflex-dom-core;
20+ variations = map (v: "reflex-dom" + v) [
21+ ""
22+ ];
23+ compilerPkgs = lib.genAttrs compilers (ghc: let
24+ variationPkgs = lib.genAttrs variations (variation: let
25+ reflex-platform = reflex-platform-fun {
26+ inherit system;
27+ haskellOverlays = [
28+ # Use this package's source for reflex
29+ (self: super: {
30+ _dep = super._dep // {
31+ reflex-dom = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [
32+ "release.nix"
33+ ".git"
34+ "dist"
35+ ])) ./.;
36+ };
37+ })
38+ ];
39+ };
40+ all = {
41+ inherit (reflex-platform.${ghc})
42+ reflex-dom-core
43+ reflex-dom
44+ ;
45+ };
46+ in all // {
47+ cache = reflex-platform.pinBuildInputs "reflex-${system}-${ghc}-${variation}"
48+ (builtins.attrValues all);
49+ });
50+ in variationPkgs // {
51+ cache = reflex-platform.pinBuildInputs "reflex-${system}-${ghc}"
52+ (map (a: a.cache) (builtins.attrValues variationPkgs));
2653 });
27− in hsPkgs // {
28− cache = reflex-platform.pinBuildInputs "reflex-dom-${system}"
29− (lib.concatLists (map builtins.attrValues (builtins.attrValues hsPkgs)));
54+ in compilerPkgs // {
55+ cache = reflex-platform.pinBuildInputs "reflex-${system}"
56+ (map (a: a.cache) (builtins.attrValues compilerPkgs));
3057 });
3158
3259 metaCache = native-reflex-platform.pinBuildInputs "reflex-dom-everywhere"