Routing.PushState
- Package
- purescript-routing
- Repository
- slamdata/purescript-routing
#PushStateInterface Source
type PushStateInterface = { listen :: (LocationState -> Effect Unit) -> Effect (Effect Unit), locationState :: Effect LocationState, pushState :: Foreign -> String -> Effect Unit, replaceState :: Foreign -> String -> Effect Unit }
A PushStateInterface
is a localized instance for making location changes
and consuming the events. Since the DOM API does not provide a general
event type for push state (only pop), you must use the coupled effects
along with listen
to receive events on all location changes.
pushState
– pushes a new location state and path onto the history stack.replaceState
– replaces the location state and path in the history stack.locationState
– Dereferences the current history statelisten
– Subscribes to location changes (both push and pop). Returns an effect which removes the listener.
#makeInterface Source
makeInterface :: Effect (PushStateInterface)
Creates a new PushStateInterface
. Generally you should only create one
instance for your application. Since the DOM does not provide general
events for location changes, listeners will only be notified on push when
using the paired functions.
#foldLocations Source
foldLocations :: forall a. (a -> LocationState -> Effect a) -> (LocationState -> Effect a) -> PushStateInterface -> Effect (Effect Unit)
Folds effectfully over location changes given callbacks for handling changes and the initial location. Returns an effect which removes the listener.
#locations Source
locations :: (Maybe LocationState -> LocationState -> Effect Unit) -> PushStateInterface -> Effect (Effect Unit)
Runs the callback on every location change providing the previous location and the latest location. Returns an effect which removes the listener.
#matches Source
matches :: forall a. Match a -> (Maybe a -> a -> Effect Unit) -> PushStateInterface -> Effect (Effect Unit)
Runs the callback on every path change using a given Match
parser to
extract a route from the path. If a path fails to parse, it is ignored.
To avoid dropping paths, provide a fallback alternative in your parser.
Returns an effect which removes the listener.
#matchesWith Source
matchesWith :: forall a f. Foldable f => (String -> f a) -> (Maybe a -> a -> Effect Unit) -> PushStateInterface -> Effect (Effect Unit)
Runs the callback on every path change using a given custom parser to extract a route from the path. If a path fails to parse, it is ignored. To avoid dropping paths, provide a fallback alternative in your parser. Returns an effect which removes the listener.