Skip to content

Commit

Permalink
Merge pull request #3 from damidevelopment/dev
Browse files Browse the repository at this point in the history
update to version 1.0.1
  • Loading branch information
hrasekj authored May 24, 2019
2 parents b346224 + ccc48e2 commit a2ead24
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
17 changes: 11 additions & 6 deletions lib/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function (_React$Component) {
_createClass(LinkBase, [{
key: "componentDidUpdate",
value: function componentDidUpdate(newProps) {
console.log('Link.componentDidUpdate');
this.setRouterState(newProps);
}
}, {
Expand Down Expand Up @@ -106,11 +105,17 @@ function (_React$Component) {
var shouldNavigateManually = refresh || openinNewTab || cmdOrCtrl || target === '_blank';

if (!shouldNavigateManually) {
e.preventDefault();
routerStore.push({
pathname: pathname,
search: search
});
if (typeof this.props.onClick === 'function') {
this.props.onClick(e);

if (!e.defaultPrevented) {
e.preventDefault();
routerStore.push({
pathname: pathname,
search: search
});
}
}
}
}
}, {
Expand Down
2 changes: 0 additions & 2 deletions lib/router-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ function () {

if (this.currentView.hasOwnProperty(slot) && route.component != null) {
// @intentionaly !=
console.log('onMatch.real', slot);

this.currentView[slot] = function () {
return typeof route.component === 'function' ? route.component(params, rootStore) : route.component;
};
Expand Down
13 changes: 5 additions & 8 deletions lib/start-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ var startRouter = function startRouter(views, rootStore) {
var path = fn.split('.');
var obj = path[0];
var action = path[1];
console.log('buildAction', resources);

if (resources.hasOwnProperty(obj) && typeof resources[obj][action] === 'function') {
runAction = resources[obj][action];
Expand Down Expand Up @@ -119,8 +118,8 @@ var startRouter = function startRouter(views, rootStore) {
// default redirect

if (!match) {
console.log('404 Not Found!'); // store.replace('notFound');

console.error('404 Not Found!');
store.replace('notFound');
return; // route = store.routes.notFound;
} // add only routes that are not currently active

Expand All @@ -138,8 +137,7 @@ var startRouter = function startRouter(views, rootStore) {
return !route.isActive || i === newPath.length - 1
/* && route !== store.currentRoute*/
;
});
console.log('lookup', newPath, oldPath); // build fns
}); // build fns

var fns = _utils.buildFnsArray.apply(void 0, _toConsumableArray(getPropValuesFromArray(oldPath, 'onExit')))
/*.map(fn => compileSyncAction(fn))*/
Expand All @@ -154,11 +152,10 @@ var startRouter = function startRouter(views, rootStore) {

for (var i = 0; i < newPath.length; i++) {
_loop(i);
}

console.log('callback fns', fns); // invoke fns
} // invoke fns
// @see https://decembersoft.com/posts/promises-in-serial-with-array-reduce/


fns.reduce(function (promiseChain, currentTask) {
return promiseChain.then(function (chainResults) {
return apply(currentTask, chainResults).then(function (currentResult) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "damidev-mobx-router",
"description": "MobX powered router for React apps",
"version": "1.0.0",
"version": "1.0.1",
"author": "Jakub Hrášek <[email protected]>",
"license": "MIT",
"bugs": {
Expand Down
11 changes: 8 additions & 3 deletions src/components/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class LinkBase extends React.Component
}

componentDidUpdate(newProps) {
console.log('Link.componentDidUpdate');
this.setRouterState(newProps);
}

Expand Down Expand Up @@ -48,8 +47,14 @@ class LinkBase extends React.Component
const shouldNavigateManually = refresh || openinNewTab || cmdOrCtrl || target === '_blank';

if (!shouldNavigateManually) {
e.preventDefault();
routerStore.push({ pathname, search });
if (typeof this.props.onClick === 'function') {
this.props.onClick(e);

if (!e.defaultPrevented) {
e.preventDefault();
routerStore.push({ pathname, search });
}
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/router-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class RouterStore

// change currentView only when slot exists and component is not empty
if (this.currentView.hasOwnProperty(slot) && route.component != null) {// @intentionaly !=
console.log('onMatch.real', slot);
this.currentView[slot] = () =>
typeof route.component === 'function' ? route.component(params, rootStore) : route.component;
}
Expand Down
9 changes: 2 additions & 7 deletions src/start-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const startRouter = (views, rootStore, { resources, ...config } = {}) =>
let obj = path[0];
let action = path[1];

console.log('buildAction', resources);
if (resources.hasOwnProperty(obj) && typeof resources[obj][action] === 'function') {
runAction = resources[obj][action];
}
Expand Down Expand Up @@ -97,8 +96,8 @@ export const startRouter = (views, rootStore, { resources, ...config } = {}) =>
// TODO: when 404 happens, should we redirect or replace?
// default redirect
if (!match) {
console.log('404 Not Found!');
// store.replace('notFound');
console.error('404 Not Found!');
store.replace('notFound');
return;
// route = store.routes.notFound;
}
Expand All @@ -114,8 +113,6 @@ export const startRouter = (views, rootStore, { resources, ...config } = {}) =>
// TODO there should be check if route params changed
newPath = newPath.filter((route, i) => !route.isActive || (i === newPath.length - 1/* && route !== store.currentRoute*/));

console.log('lookup', newPath, oldPath);

// build fns
let fns = buildFnsArray(...getPropValuesFromArray(oldPath, 'onExit'))
/*.map(fn => compileSyncAction(fn))*/;
Expand All @@ -129,8 +126,6 @@ export const startRouter = (views, rootStore, { resources, ...config } = {}) =>
);
}

console.log('callback fns', fns);

// invoke fns
// @see https://decembersoft.com/posts/promises-in-serial-with-array-reduce/
fns.reduce((promiseChain, currentTask) => {
Expand Down

0 comments on commit a2ead24

Please sign in to comment.