Skip to content

Commit

Permalink
Merge pull request #9 from InDIOS/development
Browse files Browse the repository at this point in the history
Bump to version 0.1.5
  • Loading branch information
InDIOS committed Oct 31, 2018
2 parents c6f732a + 74a575b commit 623d61e
Show file tree
Hide file tree
Showing 9 changed files with 828 additions and 891 deletions.
8 changes: 4 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"sourceType": "module"
},
"globals": {
"_$": true,
"_$d": true,
"_$sa": true,
"_$isType": true
"_$select": true,
"_$isType": true,
"_$setAttr": true,
"_$docFragment": true
},
"plugins": [
"html"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.1.5
- Added navigation ability to router instance.
- Migrated to use trebor-tools module.

0.1.4
- Fixed missing global helper.
- Updated dependencies to latest version.
Expand Down
28 changes: 16 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import RouteLink from './route-link.es';
import RouterView from './router-view.es';
import {
buildRoute, manageHooks, toPlainRoutes, pathToRegExp, generateUrl,
getHashRegExp, clearSlashes, toInternalRoute, navigate, callLeave
getHashRegExp, clearSlashes, toInternalRoute, navigate, callLeave, goToPath
} from './tools';
import { Component, InternalRoute, RouteTransition, RouterOptions, ObjectLike, NavigateParam } from './types';

Expand Down Expand Up @@ -184,30 +184,34 @@ export default class Router {
Object.defineProperty(Ctor.prototype, '$router', {
get: () => router, enumerable: true, configurable: true
});
if ($options.afterMount) {
let { afterMount } = $options;
$options.afterMount = function (this: Component) {
afterMount.call(this);
if ($options.didMount) {
let { didMount } = $options;
$options.didMount = function (this: Component) {
didMount.call(this);
navigate(this.$router);
};
} else {
$options.afterMount = function (this: Component) {
$options.didMount = function (this: Component) {
navigate(this.$router);
};
}
if ($options.afterDestroy) {
let { afterDestroy } = $options;
$options.afterDestroy = function (this: Component) {
afterDestroy.call(this);
if ($options.didDestroy) {
let { didDestroy } = $options;
$options.didDestroy = function (this: Component) {
didDestroy.call(this);
this.$router.destroy();
};
} else {
$options.afterDestroy = function (this: Component) {
$options.didDestroy = function (this: Component) {
this.$router.destroy();
};
}
}
}
}

go(path: string | number | NavigateParam) {
goToPath(this, path);
}

onUrlChange(listener: () => void) {
this._onChange.push(listener);
Expand Down
55 changes: 30 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trebor-router",
"version": "0.1.4",
"version": "0.1.5",
"description": "The Official router library for TreborJS",
"main": "lib/router.esm.js",
"scripts": {
Expand All @@ -10,16 +10,16 @@
"build:test": "npm run build:comp && npm run build:prod && rollup -c rollup.config.js --environment BUILD:test"
},
"engines": {
"node": ">=4"
"node": ">=8"
},
"peerDependencies": {
"trebor": "^0.2.4"
"dependencies": {
"trebor-tools": "^0.0.4"
},
"devDependencies": {
"rollup": "^0.66.6",
"rollup-plugin-node-resolve": "^3.4.0",
"typescript": "^3.1.3",
"trebor": "^0.2.4"
"trebor": "^0.3.2"
},
"keywords": [],
"author": "InDIOS",
Expand Down
8 changes: 4 additions & 4 deletions route-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@
default: 'null'
}
},
afterMount() {
didMount() {
this._updateURL();
this._classes = this.class;
this._path = _$isType(this.to, 'string') ? this.to : generateUrl(this.$router, this.to);
if (this.tag === 'a') _$sa(this.$refs.link, ['href', this._path]);
if (this.tag === 'a') _$setAttr(this.$refs.link, ['href', this._path]);
this.$router.onUrlChange(() => {
this._updateURL();
this.$update();
});
this.$update();
},
afterUpdate() {
didUpdate() {
if (this.parentActive !== 'null') {
let parent = !this.parentActive ? this.$refs.link.parentElement : _$(this.parentActive);
let parent = !this.parentActive ? this.$refs.link.parentElement : _$select(this.parentActive);
if (parent) {
if (this._active) {
parent.classList.add(this.activeClass);
Expand Down
4 changes: 2 additions & 2 deletions router-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
default: 'default'
}
},
beforeUnmount() {
willUnmount() {
if (this.$slots.default.hasChildNodes() && this.$parent.$hasNext) {
this.$slots.default = _$d();
this.$slots.default = _$docFragment();
}
}
};
Expand Down

0 comments on commit 623d61e

Please sign in to comment.