Module

Routing.PushState

Package
purescript-routing
Repository
slamdata/purescript-routing

#PushStateEffects Source

type PushStateEffects eff = (dom :: DOM, history :: HISTORY, ref :: REF | eff)

#PushStateInterface Source

type PushStateInterface eff = { listen :: (LocationState -> Eff eff Unit) -> Eff eff (Eff eff Unit), locationState :: Eff eff LocationState, pushState :: Foreign -> String -> Eff eff Unit, replaceState :: Foreign -> String -> Eff eff 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 state
  • listen – Subscribes to location changes (both push and pop). Returns an effect which removes the listener.

#LocationState Source

type LocationState = { hash :: String, path :: String, pathname :: String, search :: String, state :: Foreign }

#makeInterface Source

makeInterface :: forall eff. Eff (PushStateEffects eff) (PushStateInterface (PushStateEffects eff))

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 eff. (a -> LocationState -> Eff (PushStateEffects eff) a) -> (LocationState -> Eff (PushStateEffects eff) a) -> PushStateInterface (PushStateEffects eff) -> Eff (PushStateEffects eff) (Eff (PushStateEffects eff) 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 :: forall eff. (Maybe LocationState -> LocationState -> Eff (PushStateEffects eff) Unit) -> PushStateInterface (PushStateEffects eff) -> Eff (PushStateEffects eff) (Eff (PushStateEffects eff) Unit)

Runs the callback on every location change providing the previous location and the latest location. Returns an effect which removes the listener.

#foldPaths Source

foldPaths :: forall a eff. (a -> String -> Eff (PushStateEffects eff) a) -> (String -> Eff (PushStateEffects eff) a) -> PushStateInterface (PushStateEffects eff) -> Eff (PushStateEffects eff) (Eff (PushStateEffects eff) Unit)

Folds effectfully over path changes given callbacks for handling changes and the initial path. Returns an effect which removes the listener.

#paths Source

paths :: forall eff. (Maybe String -> String -> Eff (PushStateEffects eff) Unit) -> PushStateInterface (PushStateEffects eff) -> Eff (PushStateEffects eff) (Eff (PushStateEffects eff) Unit)

Runs the callback on every path change providing the previous path and the latest path. Returns an effect which removes the listener.

#matches Source

matches :: forall a eff. Match a -> (Maybe a -> a -> Eff (PushStateEffects eff) Unit) -> PushStateInterface (PushStateEffects eff) -> Eff (PushStateEffects eff) (Eff (PushStateEffects eff) 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 eff. Foldable f => (String -> f a) -> (Maybe a -> a -> Eff (PushStateEffects eff) Unit) -> PushStateInterface (PushStateEffects eff) -> Eff (PushStateEffects eff) (Eff (PushStateEffects eff) 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.