Skip to content

Commit

Permalink
Release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
majo44 committed Aug 31, 2020
1 parent d0595e2 commit d04e516
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 1.1.1
* Bugfix for double ignore event dispatch on same route navigation.
## 1.0.1
* Fix packaging.
## 1.0.0
Expand Down
19 changes: 18 additions & 1 deletion index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
routingModule,
navigate,
cancelNavigation,
StateWithRouting, RoutingEvents, PRE_NAVIGATE_EVENT
StateWithRouting, RoutingEvents, PRE_NAVIGATE_EVENT, NAVIGATION_IGNORED_EVENT
} from './index';
import * as sinon from 'sinon';
import { expect, use } from 'chai';
Expand Down Expand Up @@ -213,4 +213,21 @@ describe(`simple scenarions`, () => {
expect(store.get().routing.current.params).eql({page: 'test', 0: 'test'});
});

it('regression - when ignore navigation ignore event should be dispatched once', async () => {
const spy = sinon.fake();
let count = 0;
store.on('@dispatch', (s, e) => {
if (e[0] === NAVIGATION_IGNORED_EVENT) {
count ++;
}
});
onNavigate(store, '/a', spy);
await navigate(store, '/a');
expect(spy).to.be.calledOnce;
await navigate(store, '/a');
expect(spy).to.be.calledOnce;
await new Promise((res) => setTimeout(res));
expect(count).to.eq(1);
})

});
21 changes: 8 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,20 @@ export const routingModule = (store: StoreonStore<StateWithRouting, RoutingEvent
return;
}

return {
routing: {
...routing,
candidate: navigation,
},
};
});

// waits for sync navigation requests
// ignore all outdated candidates
// go forward just by valid one
on(PRE_NAVIGATE_EVENT, (_, { navigation }) => {
setTimeout(() => {
if (store.get().routing.candidate?.id === navigation.id) {
dispatch(NAVIGATE_EVENT, { navigation })
} else {
dispatch(NAVIGATION_IGNORED_EVENT, {navigation});
}
})
});

return {
routing: {
...routing,
candidate: navigation,
},
};
});

// if we have something ongoing
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "storeon-async-router",
"version": "1.1.0",
"version": "1.1.1",
"description": "Asynchronous router for [Storeon]",
"repository": {
"type": "git",
Expand Down

0 comments on commit d04e516

Please sign in to comment.