@cycle/history
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -86,3 +86,3 @@ /* global require */ | ||
return function historyDriver(url$) { | ||
url$.distinctUntilChanged().subscribe(createPushState(history, options.basename || "")); | ||
url$.subscribe(createPushState(history, options.basename || "")); | ||
@@ -92,4 +92,2 @@ history.listen(function (location) { | ||
}); | ||
// Convenience | ||
historySubject.location = historySubject.value; | ||
@@ -96,0 +94,0 @@ return historySubject; |
{ | ||
"name": "@cycle/history", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Cycle.js Driver based on the rackt/history library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,79 +0,15 @@ | ||
# Cycle-History | ||
# Cycle History Driver | ||
A [cycle.js](http://cycle.js.org) driver built on [history](https://github.com/rackt/history). A part of your overall routing solution. | ||
This is the standard Cycle driver for dealing with the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API). | ||
To finish the routing cycle I highly recommend [switch-path](https://github.com/staltz/switch-path), or you can provide your own. | ||
This project builds on top of the battled-tested library [rackt/history](https://github.com/rackt/history), most notably used to create React-Router. The use of this library makes this driver easy to maintain and simplifies the differences between browsers and devices. | ||
# Installation | ||
`npm install cycle-history` | ||
# Install | ||
[![npm version](https://badge.fury.io/js/%40cycle%2Fhistory.svg)](https://badge.fury.io/js/%40cycle%2Fhistory) | ||
# Usage | ||
For more concrete examples on usage, please check out [cycle-starter](https://github.com/tylors/cycle-starter) | ||
### Client-Side | ||
Define with your other drivers | ||
```javascript | ||
//import | ||
import {makeHistory, filterLinks} from 'cycle-history'; | ||
import switchPath from 'switch-path'; | ||
// Defined with your drivers | ||
History: makeHistoryDriver({ | ||
hash: false, // default, true if your browser doesn't support History API | ||
queries: true // default, toggle QuerySupport | ||
basename: '' // default, sets up BasenameSupport | ||
// all other history Options | ||
}) | ||
// Use in Main - shown in conjunction with switch-path | ||
function main({DOM, History}) { | ||
const pathValue$ = History.map(location => { // History Location Object | ||
let {path, value} = switchPath(location.pathname, routes) | ||
return [path, value] | ||
}); | ||
const url$ = DOM.select('a').events('click').filter(filterLinks) | ||
// filterLinks will make sure this is a path we want to handle | ||
// Best to provide more precise selectors to avoid this need. | ||
return { | ||
... | ||
History: url$ | ||
} | ||
} | ||
This package is available on npm and is installable using the following command. | ||
``` | ||
[Info on QuerySupport](https://github.com/rackt/history/blob/master/docs/QuerySupport.md) | ||
[Info on BasenameSupport](https://github.com/rackt/history/blob/master/docs/BasenameSupport.md) | ||
### Server-Side | ||
Following @staltz [isomorphic example](https://github.com/cyclejs/cycle-examples/blob/master/isomorphic/server.js) | ||
```javascript | ||
// server.js | ||
// Lines 27-37 become | ||
function wrapAppResultWithBoilerplate(appFn, bundle$) { | ||
return function wrappedAppFn(ext) { | ||
let requests = appFn(ext); | ||
let wrappedVTree$ = Rx.Observable.combineLatest(requests.DOM, bundle$, | ||
wrapVTreeWithHTMLBoilerplate | ||
); | ||
return { | ||
DOM: wrappedVTree$, | ||
History: requests.History | ||
}; | ||
}; | ||
} | ||
// Lines 71-74 become | ||
let [requests, responses] = Cycle.run(wrappedAppFn, { | ||
DOM: makeHTMLDriver(), | ||
History: makeServerHistoryDriver({ | ||
pathname: req.url | ||
}) | ||
}); | ||
$ npm install @cycle/history | ||
``` | ||
`makeServerHistoryDriver()` accepts all options allowed in a [Location](https://github.com/rackt/history/blob/master/docs/Location.md) as well as the extra options provided by BasenameSupport and QuerySupport, each respectively can be found [here](https://github.com/rackt/history/blob/master/docs/BasenameSupport.md) and [here](https://github.com/rackt/history/blob/master/docs/QuerySupport.md). Simple defaults are provided if not supplied. | ||
In @staltz isomorphic example, you can remove all references to context$ if it is now unneeded for your application. | ||
Documentation can be found [here](https://github.com/cyclejs/cycle-history/tree/master/docs/). |
@@ -62,8 +62,5 @@ /* global require */ | ||
url$ | ||
.distinctUntilChanged() | ||
.subscribe(createPushState(history, options.basename || ``)) | ||
history.listen(location => historySubject.onNext(location)) | ||
// Convenience | ||
historySubject.location = historySubject.value | ||
@@ -81,3 +78,3 @@ return historySubject | ||
action = `POP`, | ||
key = `` | ||
key = ``, | ||
} = startingLocation || {} | ||
@@ -92,3 +89,3 @@ | ||
action, | ||
key | ||
key, | ||
}) | ||
@@ -95,0 +92,0 @@ } |
/* global require */ | ||
const test = require(`tape`) | ||
const {Rx} = require(`rx`) | ||
const Rx = require(`rx`) | ||
const { | ||
@@ -5,0 +5,0 @@ makeHistoryDriver, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1135382
132
3
19795
16