reflex-dom-contrib-0.3: A playground for experimenting with infrastructure and common code for reflex applications

Safe HaskellNone
LanguageHaskell2010

Reflex.Dom.Contrib.Widgets.BoundedList

Synopsis

Documentation

boundedSelectList Source

Arguments

:: (MonadWidget t m, Show k, Ord k, Show v) 
=> Limit

Maximum number of items to keep in the DOM at a time

-> Dynamic t a

Currently selected item. New items are added to the list when the currently selected item changes and the new item is not already in the list.

-> Event t (Map k v -> Map k v) 
-> (a -> k)

Gets the portion of a used as the key for the map of items

-> (a -> Maybe a)

Decides whether to run expensiveGetNew in the case that the key is already in the cache.

-> (Event t a -> m (Event t (k, v)))

Gets a new key/value pair. This function is run when curSelected changes.

-> b

Default value to return if nothing is in the list

-> (k -> Dynamic t v -> Dynamic t Bool -> m b)

Function to render a single item

-> m (Dynamic t b) 

Implements a common use of boundedSelectList' where only the currently selected item from a list is displayed. In this case a Dynamic representing the current selection is used to drive insertions and they are never deleted externally. Instead of returning a Map of all the item results, this function only returns the result for the item that is currently selected.

boundedSelectList' Source

Arguments

:: (MonadWidget t m, Show k, Ord k, Show v) 
=> Limit

Maximum number of items to keep in the DOM at a time

-> Dynamic t k

Currently selected item

-> Event t (Map k v -> Map k v)

Event that updates individual item values

-> ReflexMap t k v

Interface for updating the list

-> (k -> Dynamic t v -> Dynamic t Bool -> m a)

Function to render a single item

-> m (Dynamic t (Map k a)) 

A widget with generalized handling for dynamically sized lists. There are many possible approaches to rendering lists that have one visible current selection. One way is to keep all the items in the DOM and manage the selection by managing visibility through something like display:none or visibility:hidden. Another way is to only keep the currently selected item in the DOM and swap it out every time the selection is changed.

The problem with keeping all items in the DOM is that this might use too much memory either because there are many items or the items are large. The problem with keeping only the currently selected item in the DOM is that performance might be too slow if removing the old item's DOM elements and building the new one takes too long.

This widget provides a middle ground. It lets the user decide how many elements are kept in the DOM at any one time and prunes the least recently used items if that size is exceeded.

mkHiding Source

Arguments

:: MonadWidget t m 
=> Map String String 
-> m a 
-> Dynamic t Bool

Function of a dynamic active flag

-> m a 

Wraps a widget with a dynamically hidden div that uses display:none to hide.

keyToMaybe :: MonadWidget t m => (Event t a -> m (Event t (b, c))) -> Event t (Maybe a) -> m (Event t (Maybe b, c)) Source

Small helper for a common pattern that comes up with the expensiveGetNew parameter to boundedSelectList.