Skip to content

Commit 4bf702f

Browse files
Merge branch 'master' into bump-dependencies
2 parents 08def33 + 758d044 commit 4bf702f

File tree

11 files changed

+25
-27
lines changed

11 files changed

+25
-27
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/dist
22
/node_modules
33
/npm-debug.log
4+
package-lock.json
45
/match.js
56
/*.d.ts
67
.DS_Store

Diff for: README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ render(
120120
`<Link>` is just a normal link, but it automatically adds and removes an "active" classname to itself based on whether it matches the current URL.
121121

122122
```js
123-
import { Router } from 'preact-router';
124-
import { Link } from 'preact-router/match';
123+
import { Router, Link } from 'preact-router';
125124

126125
render(
127126
<div>

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "preact-router",
33
"amdName": "preactRouter",
4-
"version": "2.6.1",
4+
"version": "3.0.0",
55
"description": "Connect your components up to that address bar.",
66
"main": "dist/preact-router.js",
77
"jsnext:main": "dist/preact-router.es.js",
@@ -45,7 +45,7 @@
4545
},
4646
"homepage": "https://github.com/developit/preact-router",
4747
"peerDependencies": {
48-
"preact": "*"
48+
"preact": ">=10 || ^10.0.0-beta.0"
4949
},
5050
"devDependencies": {
5151
"babel-cli": "^6.9.0",
@@ -76,7 +76,7 @@
7676
"mocha": "^5.2.0",
7777
"npm-run-all": "^3.0.0",
7878
"phantomjs-prebuilt": "^2.1.7",
79-
"preact": "^8.0.1",
79+
"preact": "^10.0.0-beta.0",
8080
"pretty-bytes-cli": "^1.0.0",
8181
"puppeteer": "^1.9.0",
8282
"rimraf": "^2.5.1",
@@ -88,7 +88,7 @@
8888
"rollup-plugin-uglify": "^1.0.1",
8989
"sinon": "^7.1.0",
9090
"sinon-chai": "^2.8.0",
91-
"typescript": "^2.5.3",
91+
"typescript": "^3.4.4",
9292
"webpack": "^1.13.1"
9393
}
9494
}

Diff for: src/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function Route<Props>(
6262
props: RouteProps<Props> & Partial<Props>
6363
): preact.VNode;
6464

65-
export function Link(props: {activeClassName?: string} & JSX.HTMLAttributes): preact.VNode;
65+
export function Link(props: {activeClassName?: string} & preact.JSX.HTMLAttributes): preact.VNode;
6666

6767
declare module 'preact' {
6868
export interface Attributes extends RoutableProps {}

Diff for: src/index.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloneElement, h, Component } from 'preact';
1+
import { cloneElement, createElement, Component, toChildArray } from 'preact';
22
import { exec, prepareVNodeForRanking, assign, pathRankSort } from './util';
33

44
let customHistory = null;
@@ -9,10 +9,6 @@ const subscribers = [];
99

1010
const EMPTY = {};
1111

12-
function isPreactElement(node) {
13-
return node.__preactattr_!=null || typeof Symbol!=='undefined' && node[Symbol.for('preactattr')]!=null;
14-
}
15-
1612
function setUrl(url, type='push') {
1713
if (customHistory && customHistory[type]) {
1814
customHistory[type](url);
@@ -117,7 +113,7 @@ function delegateLinkHandler(e) {
117113

118114
let t = e.target;
119115
do {
120-
if (String(t.nodeName).toUpperCase()==='A' && t.getAttribute('href') && isPreactElement(t)) {
116+
if (String(t.nodeName).toUpperCase()==='A' && t.getAttribute('href')) {
121117
if (t.hasAttribute('native')) return;
122118
// if link is handled by the router, prevent browser defaults
123119
if (routeFromLink(t)) {
@@ -166,7 +162,8 @@ class Router extends Component {
166162

167163
/** Check if the given URL can be matched against any children */
168164
canRoute(url) {
169-
return this.getMatchingChildren(this.props.children, url, false).length > 0;
165+
const children = toChildArray(this.props.children);
166+
return this.getMatchingChildren(children, url, false).length > 0;
170167
}
171168

172169
/** Re-render children with a new URL to match against. */
@@ -213,7 +210,7 @@ class Router extends Component {
213210
.filter(prepareVNodeForRanking)
214211
.sort(pathRankSort)
215212
.map( vnode => {
216-
let matches = exec(url, vnode.attributes.path, vnode.attributes);
213+
let matches = exec(url, vnode.props.path, vnode.props);
217214
if (matches) {
218215
if (invoke !== false) {
219216
let newProps = { url, matches };
@@ -228,7 +225,7 @@ class Router extends Component {
228225
}
229226

230227
render({ children, onChange }, { url }) {
231-
let active = this.getMatchingChildren(children, url, true);
228+
let active = this.getMatchingChildren(toChildArray(children), url, true);
232229

233230
let current = active[0] || null;
234231
this._didRoute = !!current;
@@ -252,10 +249,10 @@ class Router extends Component {
252249
}
253250

254251
const Link = (props) => (
255-
h('a', assign({ onClick: handleLinkClick }, props))
252+
createElement('a', assign({ onClick: handleLinkClick }, props))
256253
);
257254

258-
const Route = props => h(props.component, props);
255+
const Route = props => createElement(props.component, props);
259256

260257
Router.subscribers = subscribers;
261258
Router.getCurrentUrl = getCurrentUrl;

Diff for: src/match.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export class Match extends preact.Component<RoutableProps, {}> {
66
render(): preact.VNode;
77
}
88

9-
export interface LinkProps extends JSX.HTMLAttributes {
9+
export interface LinkProps extends preact.JSX.HTMLAttributes {
1010
activeClassName: string;
11+
children?: preact.ComponentChildren;
1112
}
1213

1314
export function Link(props: LinkProps): preact.VNode;

Diff for: src/match.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class Match extends Component {
1616
let url = this.nextUrl || getCurrentUrl(),
1717
path = url.replace(/\?.+$/,'');
1818
this.nextUrl = null;
19-
return props.children[0] && props.children[0]({
19+
return props.children({
2020
url,
2121
path,
2222
matches: path===props.path

Diff for: src/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function pathRankSort(a, b) {
6262
export function prepareVNodeForRanking(vnode, index) {
6363
vnode.index = index;
6464
vnode.rank = rankChild(vnode);
65-
return vnode.attributes;
65+
return vnode.props;
6666
}
6767

6868
export function segmentize(url) {
@@ -78,5 +78,5 @@ export function rank(path) {
7878
}
7979

8080
function rankChild(vnode) {
81-
return vnode.attributes.default ? 0 : rank(vnode.attributes.path);
81+
return vnode.props.default ? 0 : rank(vnode.props.path);
8282
}

Diff for: test/dom.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('dom', () => {
1717
scratch = document.createElement('div');
1818
document.body.appendChild(scratch);
1919
$ = s => scratch.querySelector(s);
20-
mount = jsx => render(jsx, scratch, scratch.firstChild);
20+
mount = jsx => {render(jsx, scratch); return scratch.lastChild;};
2121
});
2222

2323
beforeEach( () => {

Diff for: test/util.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('util', () => {
4343

4444
describe('pathRankSort', () => {
4545
it('should sort by highest rank first', () => {
46-
let paths = arr => arr.map( path => ({ attributes:{path}} ) );
46+
let paths = arr => arr.map( path => ({ props:{path}} ) );
4747
let clean = vnode => { delete vnode.rank; delete vnode.index; return vnode; };
4848

4949
expect(
@@ -54,10 +54,10 @@ describe('util', () => {
5454
});
5555

5656
it('should return default routes last', () => {
57-
let paths = arr => arr.map( path => ({attributes:{path}}) );
57+
let paths = arr => arr.map( path => ({props:{path}}) );
5858
let clean = vnode => { delete vnode.rank; delete vnode.index; return vnode; };
5959

60-
let defaultPath = {attributes:{default:true}};
60+
let defaultPath = {props:{default:true}};
6161
let p = paths(['/a/b/', '/a/b', '/', 'b']);
6262
p.splice(2,0,defaultPath);
6363

Diff for: test_helpers/assert-clone-of.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default function assertCloneOf({ Assertion }) {
44
if (Assertion.__assertCloneOfMounted === true) return;
55
Assertion.__assertCloneOfMounted = true;
66

7-
Assertion.addMethod('cloneOf', function(routeJsx, { matches = {}, url = this._obj.attributes.path } = {}) {
7+
Assertion.addMethod('cloneOf', function(routeJsx, { matches = {}, url = this._obj.props.path } = {}) {
88
const vnode = this._obj;
99
const clonedRoute = cloneElement(routeJsx, { url, matches, ...matches });
1010
new chai.Assertion(vnode).to.be.eql(clonedRoute);

0 commit comments

Comments
 (0)