carry-history.core

add

(add blueprint history)

Applies middleware which syncs app model with browser history.

After start it begins catching history events and updates ::token in model accordingly. If ::token changes in model (e.g. by toggling action in debugger), then current url is replaced using new token. Initial ::token value will be applied on clicking debugger’s Reset.

Sends [::on-enter token] signal to app after handling token change event initiated from browser (e.g. on clicking Back button). So using HistoryProtocol’s replace-token/push-token would not trigger this signal. You can still force sending this signal by passing {:treat-as-browser-event? true} event-data to these functions.

Middleware is friendly to carry-debugger: it won’t automatically dispatch initial signal on app start if debugger’s replay mode is on.

HistoryProtocol

protocol

Protocol for objects managing browser history.

members

token->href

(token->href this token)

Returns the href for the specified token to be used in HTML links.

replace-token

(replace-token this token)(replace-token this token event-data)

Replace token and fire an event with additional data passed (data is nil if not specified); do nothing if current token is already equal to the specified one.

push-token

(push-token this token)(push-token this token event-data)

Push token and fire an event with additional data passed (data is nil if not specified); do nothing if current token is already equal to the specified one.

token

(token this)

Return current token.

listen

(listen this callback)

Starts calling back on history events. Callback function signature: [token browser-event? event-data], where:

  • token - new token
  • browser-event? - true if event was initiated by action in browser, e.g. clicking Back button
  • event-data - data which was passed from replace-token/push-token

Returns a function which stops listening.

new-hash-history

(new-hash-history)

For history management using hashes based on onhashchange event. Will not correctly work in Opera Mini: http://caniuse.com/#search=hash

new-history

(new-history)

For history management using pushState. Supported browsers: http://caniuse.com/#search=pushstate

new-legacy-hash-history

(new-legacy-hash-history)

For history management using hashes. Should work in Opera Mini.