From d04e516d36675b48605baaff85fd729fb73bf449 Mon Sep 17 00:00:00 2001 From: majo44 Date: Mon, 31 Aug 2020 13:22:53 +0200 Subject: [PATCH] Release 1.1.1 --- CHANGELOG.md | 2 ++ index.spec.ts | 19 ++++++++++++++++++- index.ts | 21 ++++++++------------- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd3f8a0..8ffc452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/index.spec.ts b/index.spec.ts index be04aa1..0df6e8d 100644 --- a/index.spec.ts +++ b/index.spec.ts @@ -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'; @@ -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); + }) + }); diff --git a/index.ts b/index.ts index a9dab37..b1d61c0 100644 --- a/index.ts +++ b/index.ts @@ -174,25 +174,20 @@ export const routingModule = (store: StoreonStore { 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 diff --git a/package-lock.json b/package-lock.json index 7a5e1c7..23576bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "storeon-async-router", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e5750dd..a5f5686 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "storeon-async-router", - "version": "1.1.0", + "version": "1.1.1", "description": "Asynchronous router for [Storeon]", "repository": { "type": "git",