Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ui-router/core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.0.23
Choose a base ref
...
head repository: ui-router/core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6.0.1
Choose a head ref
Loading
Showing with 1,247 additions and 1,261 deletions.
  1. +12 −10 .travis.yml
  2. +31 −0 CHANGELOG.md
  3. +15 −15 package.json
  4. +4 −1 src/resolve/interface.ts
  5. +6 −20 src/resolve/resolvable.ts
  6. +1 −1 src/transition/interface.ts
  7. +52 −14 test/resolveSpec.ts
  8. +1,126 −1,200 yarn.lock
22 changes: 12 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
language: node_js
node_js: 8.9.1
node_js: 10.16.0
services:
- xvfb
before_install:
- sh -e /etc/init.d/xvfb start
- export PATH=$HOME/.yarn/bin:$PATH
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.5.1
- sudo apt-get install libgconf-2-4
- export PATH=$HOME/.yarn/bin:$PATH
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.5.1
script:
- tsc &&
yarn test &&
yarn docs &&
yarn test:downstream
- tsc &&
yarn test &&
yarn docs &&
yarn test:downstream
env:
notifications:
slack:
@@ -20,5 +22,5 @@ git:
depth: 3
cache:
directories:
- node_modules
- ".downstream_cache"
- node_modules
- '.downstream_cache'
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## 6.0.1 (2019-09-27)
[Compare `@uirouter/core` versions 6.0.0 and 6.0.1](https://github.com/ui-router/core/compare/6.0.0...6.0.1)

### Bug Fixes

* **resolve:** remove unnecessary generics from CustomAsyncPolicy ([#452](https://github.com/ui-router/core/issues/452)) ([61f4ee9](https://github.com/ui-router/core/commit/61f4ee9))




# 6.0.0 (2019-09-26)
[Compare `@uirouter/core` versions 5.0.23 and 6.0.0](https://github.com/ui-router/core/compare/5.0.23...6.0.0)

### Bug Fixes

* **travis:** use service: xvfb instead of launching it manually ([1271fcd](https://github.com/ui-router/core/commit/1271fcd))
* **travis:** use service: xvfb instead of launching it manually. install libgconf debian package ([ac1ef4b](https://github.com/ui-router/core/commit/ac1ef4b))


### Features

* **resolve:** Remove RXWAIT async policy in favour of allowing user defined async policy function ([#366](https://github.com/ui-router/core/issues/366)) ([0ad87f6](https://github.com/ui-router/core/commit/0ad87f6))


### BREAKING CHANGES

* **resolve:** RXWAIT async policy has been removed, but it never worked in the first place




## 5.0.23 (2019-01-28)
[Compare `@uirouter/core` versions 5.0.22 and 5.0.23](https://github.com/ui-router/core/compare/5.0.22...5.0.23)

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@uirouter/core",
"description": "UI-Router Core: Framework agnostic, State-based routing for JavaScript Single Page Apps",
"version": "5.0.23",
"version": "6.0.1",
"scripts": {
"clean": "shx rm -rf lib lib-esm _bundles .cache _doc",
"compile": "npm run clean && tsc && tsc -m es6 --outDir lib-esm && shx cp src/*.json lib",
@@ -66,31 +66,31 @@
"module": "lib-esm/index.js",
"license": "MIT",
"devDependencies": {
"@types/jasmine": "^3.3.5",
"@types/jasmine": "^3.3.13",
"@types/jquery": "^3.3.2",
"@uirouter/publish-scripts": "^2.3.25",
"@uirouter/publish-scripts": "^2.3.26",
"dts-downlevel": "^0.3.0",
"fork-ts-checker-webpack-plugin": "^0.5.2",
"husky": "^1.3.1",
"fork-ts-checker-webpack-plugin": "^1.3.7",
"husky": "^3.0.0",
"jasmine-core": "^3.3.0",
"karma": "^4.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "^2.0.1",
"karma-script-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.5",
"prettier": "^1.15.3",
"pretty-quick": "^1.6.0",
"rollup": "^1.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"karma-webpack": "^4.0.2",
"prettier": "^1.18.2",
"pretty-quick": "^1.11.1",
"rollup": "^1.15.5",
"rollup-plugin-node-resolve": "^5.0.2",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^6.0.0",
"ts-loader": "^5.3.3",
"tslint": "^5.12.0",
"ts-loader": "^6.0.2",
"tslint": "^5.17.0",
"tslint-eslint-rules": "^5.3.1",
"typescript": "^3.2.2",
"webpack": "^4.28.1"
"typescript": "^3.5.2",
"webpack": "^4.34.0"
},
"husky": {
"hooks": {
5 changes: 4 additions & 1 deletion src/resolve/interface.ts
Original file line number Diff line number Diff line change
@@ -200,7 +200,10 @@ export interface ResolvePolicy {
}

export type PolicyWhen = 'LAZY' | 'EAGER';
export type PolicyAsync = 'WAIT' | 'NOWAIT' | 'RXWAIT';
export type PolicyAsync = 'WAIT' | 'NOWAIT' | CustomAsyncPolicy;
export interface CustomAsyncPolicy {
(data: any): Promise<any>;
}

/** @internalapi */
export let resolvePolicies = {
26 changes: 6 additions & 20 deletions src/resolve/resolvable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @publicapi @module resolve */ /** */
import { extend, equals, inArray, identity } from '../common/common';
import { extend, identity } from '../common/common';
import { services } from '../common/coreservices';
import { trace } from '../common/trace';
import { ResolvePolicy, ResolvableLiteral, resolvePolicies } from './interface';
import { ResolvePolicy, ResolvableLiteral, PolicyAsync } from './interface';

import { ResolveContext } from './resolveContext';
import { stringify } from '../common/strings';
@@ -117,26 +117,12 @@ export class Resolvable implements ResolvableLiteral {
// Invokes the resolve function passing the resolved dependencies as arguments
const invokeResolveFn = (resolvedDeps: any[]) => this.resolveFn.apply(null, resolvedDeps);

/**
* For RXWAIT policy:
*
* Given an observable returned from a resolve function:
* - enables .cache() mode (this allows multicast subscribers)
* - then calls toPromise() (this triggers subscribe() and thus fetches)
* - Waits for the promise, then return the cached observable (not the first emitted value).
*/
const waitForRx = (observable$: any) => {
const cached = observable$.cache(1);
return cached
.take(1)
.toPromise()
.then(() => cached);
};

// If the resolve policy is RXWAIT, wait for the observable to emit something. otherwise pass through.
const node: PathNode = resolveContext.findNode(this);
const state: StateObject = node && node.state;
const maybeWaitForRx = this.getPolicy(state).async === 'RXWAIT' ? waitForRx : identity;

const asyncPolicy: PolicyAsync = this.getPolicy(state).async;
const customAsyncPolicy = isFunction(asyncPolicy) ? asyncPolicy : identity;

// After the final value has been resolved, update the state of the Resolvable
const applyResolvedValue = (resolvedValue: any) => {
@@ -152,7 +138,7 @@ export class Resolvable implements ResolvableLiteral {
.when()
.then(getResolvableDependencies)
.then(invokeResolveFn)
.then(maybeWaitForRx)
.then(customAsyncPolicy)
.then(applyResolvedValue));
}

2 changes: 1 addition & 1 deletion src/transition/interface.ts
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ export interface TransitionHookOptions {
*/
export interface TreeChanges {
/** @nodoc */
[key: string]: PathNode[];
[key: string]: PathNode[] | undefined;

/** The path of nodes in the state tree that the transition is coming *from* */
from: PathNode[];
66 changes: 52 additions & 14 deletions test/resolveSpec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ResolveContext, StateObject, PathNode, Resolvable, copy } from '../src/index';
import { tail } from '../src/common/common';
import { services } from '../src/common/coreservices';
import { tree2Array } from './_testUtils';
import { copy, CustomAsyncPolicy, PathNode, Resolvable, ResolveContext, StateObject } from '../src/index';
import { UIRouter } from '../src/router';

import { TestingPlugin } from './_testingPlugin';
import { StateRegistry } from '../src/state/stateRegistry';
import { StateService } from '../src/state/stateService';
import { TransitionService } from '../src/transition/transitionService';
import { StateRegistry } from '../src/state/stateRegistry';
import { tail } from '../src/common/common';

import { TestingPlugin } from './_testingPlugin';
import { tree2Array } from './_testUtils';

///////////////////////////////////////////////

@@ -426,6 +426,7 @@ describe('Resolvables system:', function() {
const ctx = new ResolveContext(path);

let result;

function checkCounts() {
expect(result).toBe('JJ2K');
expect(counts['_J']).toBe(1);
@@ -561,10 +562,11 @@ describe('Resolvables system:', function() {

describe('NOWAIT Resolve Policy', () => {
it('should allow a transition to complete before the resolve is settled', async done => {
let resolve,
resolvePromise = new Promise(_resolve => {
resolve = _resolve;
});
let resolve;

const resolvePromise = new Promise(_resolve => {
resolve = _resolve;
});

$registry.register({
name: 'nowait',
@@ -599,10 +601,11 @@ describe('Resolvables system:', function() {
});

it('should wait for WAIT resolves and not wait for NOWAIT resolves', async done => {
let promiseResolveFn,
resolvePromise = new Promise(resolve => {
promiseResolveFn = resolve;
});
let promiseResolveFn;

const resolvePromise = new Promise(resolve => {
promiseResolveFn = resolve;
});

$registry.register({
name: 'nowait',
@@ -635,4 +638,39 @@ describe('Resolvables system:', function() {
$state.go('nowait');
});
});

describe('custom Resolve Policy', () => {
let customResolvePolicy: CustomAsyncPolicy;

it('should wait for the promise to resolve before finishing the transition', async done => {
let resolve: (value: string) => void;

const resolvePromise: Promise<string> = new Promise(_resolve => {
resolve = _resolve;
});

customResolvePolicy = jasmine.createSpy('customResolvePolicy');

(customResolvePolicy as jasmine.Spy).and.callFake((data: { useMe: Promise<string> }) => {
return data.useMe;
});

resolve('myAwaitedValue');

$registry.register({
name: 'customPolicy',
resolve: {
customWait: () => ({ useMe: resolvePromise }),
},
resolvePolicy: { async: customResolvePolicy },
});

$transitions.onSuccess({}, trans => {
expect(customResolvePolicy).toHaveBeenCalledWith({ useMe: resolvePromise });
expect(trans.injector().get('customWait')).toBe('myAwaitedValue');
});

$state.go('customPolicy').then(done);
});
});
});
Loading