Skip to content

Commit

Permalink
docs(Transition): Document UrlRouter as internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Jan 13, 2017
1 parent fc571a2 commit 588dd99
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/url/urlRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ defaultRuleSortFn = composeSort(
*
* ### Deprecation warning:
* This class is now considered to be an internal API
* For configuring URL rules, use the [[UrlRulesApi]] which can be found on [[UrlService.rules]].
* Use the [[UrlService]] instead.
* For configuring URL rules, use the [[UrlRulesApi]] which can be found as [[UrlService.rules]].
*
* This class updates the URL when the state changes.
* It also responds to changes in the URL.
Expand Down
18 changes: 12 additions & 6 deletions src/vanilla/hashLocation.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
/**
* @internalapi
* @module vanilla
*/ /** */
*/
/** */
import { isDefined } from "../common/index";
import { LocationServices } from "../common/coreservices";
import { splitHash, splitQuery, trimHashVal, getParams, locationPluginFactory, buildUrl } from "./utils";
import { UIRouter } from "../router";
import { LocationPlugin } from "./interface";
import { LocationPlugin, LocationLike, HistoryLike } from "./interface";
import { pushTo, deregAll } from "../common/common";
import { Disposable } from "../interface";
import { BrowserLocationConfig } from "./browserLocationConfig";

/** A `LocationServices` that uses the browser hash "#" to get/set the current location */
export class HashLocationService implements LocationServices, Disposable {
private _listeners: Function[] = [];
_location: LocationLike;
_history: HistoryLike;

hash = () => splitHash(trimHashVal(location.hash))[1];
path = () => splitHash(splitQuery(trimHashVal(location.hash))[0])[0];
search = () => getParams(splitQuery(splitHash(trimHashVal(location.hash))[0])[1]);
_getHash = () => trimHashVal(this._location.hash);
_setHash = (val) => this._location.hash = val;

hash = () => splitHash(this._getHash())[1];
path = () => splitHash(splitQuery(this._getHash())[0])[0];
search = () => getParams(splitQuery(splitHash(this._getHash())[0])[1]);

url(url?: string, replace: boolean = true): string {
if (isDefined(url)) location.hash = url;
if (isDefined(url)) this._setHash(url);
return buildUrl(this);
}

Expand Down
13 changes: 13 additions & 0 deletions src/vanilla/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ export interface ServicesPlugin extends UIRouterPlugin {
$q: $QLike,
$injector: $InjectorLike
}

export interface LocationLike {
hash: string;
pathname: string;
search: string;
}

export interface HistoryLike {
back(distance?: any): void;
forward(distance?: any): void;
pushState(statedata: any, title?: string, url?: string): void;
replaceState(statedata: any, title?: string, url?: string): void;
}
8 changes: 4 additions & 4 deletions src/vanilla/pushStateLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { isDefined } from "../common/index";
import { LocationServices, LocationConfig } from "../common/coreservices";
import { splitQuery, trimHashVal, getParams, locationPluginFactory, buildUrl } from "./utils";
import { LocationPlugin } from "./interface";
import { LocationPlugin, HistoryLike, LocationLike } from "./interface";
import { UIRouter } from "../router";
import { pushTo, deregAll } from "../common/common";
import { Disposable } from "../interface";
Expand All @@ -18,9 +18,9 @@ import { BrowserLocationConfig } from "./browserLocationConfig";
*/
export class PushStateLocationService implements LocationServices, Disposable {
private _listeners: Function[] = [];
private _location: Location;
private _history: History;
private _config: LocationConfig;
_location: LocationLike;
_history: HistoryLike;
_config: LocationConfig;

constructor(router: UIRouter) {
this._location = location;
Expand Down

0 comments on commit 588dd99

Please sign in to comment.