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 tokenbrowser-event?-trueif event was initiated by action in browser, e.g. clicking Back buttonevent-data- data which was passed fromreplace-token/push-token
Returns a function which stops listening.
link
(link history token {:keys [replace?], :as attrs} & body)Link Reagent component which changes current URL without sending request to server. Will replace current token instead of pushing if :replace? attribute is true (attribute is false by default).
If history middleware is added then clicking the link will produce :on-enter signal.
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.