MyGit

0.5.0

ui-router/react

版本发布时间: 2017-05-25 18:59:37

ui-router/react最新发布版本:1.0.7(2021-07-27 08:03:58)

Bug Fixes

Features

BREAKING CHANGES

@uirouter/core changes

5.0.3 (2017-05-24)

Bug Fixes

Features

BREAKING CHANGES

TransitionHook: Transition hooks no longer expose the internal State object (now named StateObject)

Before:

import { State } from "ui-router-core";
const match = { to: (state: State) => state.data.auth };
transitionsvc.onEnter(match, (trans: Transition, state: State) => {
  // state is the internal State object
  if (state.includes["foo"]) { // internal ui-router API
    return false;
  }
}

Now:

import { StateDeclaration } from "@uirouter/react";
const match = { to: (state: StateDeclaration) => state.data.auth };
transitionsvc.onEnter(match, (trans: Transition, state: StateDeclaration) => {
  // state === the state object you registered
  // Access internal ui-router API using $$state()
  if (state.$$state().includes["foo"]) {
    return false;
  }
}

Motivation:

The State object (now named StateObject) is an internal API and should not be exposed via any public APIs. If you depend on the internal APIs, you can still access the internal object by calling state.$$state().

StateObject: Renamed internal API State object to StateObject

Before:

import {State} from "ui-router-core";

Now:

import {StateObject} from "@uirouter/react";

Motivation:

We'd like to use the State name/symbol as a public API. It will be an ES7/TS decorator for ES6/TS state definition classes, i.e:

@State("foo")
export class FooState implements StateDeclaration {
  url = "/foo";
  component = FooComponent;

  @Resolve({ deps: [FooService] })
  fooData(fooService) {
    return fooService.getFoos();
  }
}

Transition: All Transition errors are now wrapped in a Rejection object.

Before:

Previously, if a transition hook returned a rejected promise:

.onStart({}, () => Promise.reject('reject transition'));

In onError or transtion.promise.catch(), the raw rejection was returned:

.onError({}, (trans, err) => err === 'reject transition')

Now:

Now, the error is wrapped in a Rejection object.

.onError({}, (trans, err) =>
    err instanceof Rejection && err.detail === 'reject transition')
.onError({}, (trans, err) => {
  err.type === RejectType.ABORTED === 3
});

Motivation:

Errors thrown from a hook and rejection values returned from a hook can now be processed in the same way.

onBefore: onBefore hooks are now run asynchronously like all the other hooks.

Old behavior

Previously, the onBefore hooks were run in the same stackframe as transitionTo. If they threw an error, it could be caught using try/catch.

transitionService.onBefore({ to: 'foo' }), () => { throw new Error('doh'); });
try {
  stateService.go('foo');
} catch (error) {
  // handle error
}

New behavior

Now, onBefore hooks are processed asynchronously. To handle errors, use any of the async error handling paradigms:

Motivation

Why introduce a BC?

defaultErrorHandler: ABORTED transitions do not invoke the defaultErrorHandler

Returning false from a transition hook will abort the transition.

Old behavior

Previously, this case was considered an error and was logged by defaultErrorHandler. After your feedback, we agree that this is not typically an error.

New behavior

Now, aborted transitions do not trigger the defaultErrorHandler

Motivation

Most users do not consider ABORT to be an error. The default error handler should match this assumption.

相关地址:原始地址 下载(tar) 下载(zip)

查看:2017-05-25发行的版本