Skip to content

Commit 31ac53c

Browse files
refactor(vanilla): Rename from history to location
1 parent 41157fc commit 31ac53c

12 files changed

+41
-58
lines changed

src/vanilla/hashHistory.ts renamed to src/vanilla/hashLocation.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import {services, isDefined} from '../common/module';
22
import {LocationConfig, LocationServices} from '../common/coreservices';
3-
import {HistoryImplementation} from './interface';
43
import {splitHash, splitQuery, trimHashVal, getParams} from './utils';
54

65
let hashPrefix: string = '';
76
let baseHref: string = '';
87

9-
const locationServiceConfig: LocationConfig = {
8+
export const hashLocationConfig: LocationConfig = {
109
port: () =>
1110
parseInt(location.port),
1211
protocol: () =>
@@ -23,9 +22,9 @@ const locationServiceConfig: LocationConfig = {
2322
}
2423
return hashPrefix;
2524
}
26-
}
25+
};
2726

28-
const locationService: LocationServices = {
27+
export const hashLocationService: LocationServices = {
2928
hash: () =>
3029
splitHash(trimHashVal(location.hash))[1],
3130
path: () =>
@@ -36,9 +35,4 @@ const locationService: LocationServices = {
3635
if (url) location.hash = url;
3736
},
3837
onChange: (cb: EventListener) => window.addEventListener("hashchange", cb, false) as any
39-
}
40-
41-
export const hashHistory: HistoryImplementation = {
42-
service: locationService,
43-
configuration: locationServiceConfig
44-
}
38+
};

src/vanilla/index.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
/**
22
* Naive, pure JS implementation of core ui-router services
33
*
4-
* @module vanilla
4+
* @internalapi @module vanilla
55
*/ /** */
66
import { UIRouter } from "../router";
77

8-
import { services as coreservices } from "../common/coreservices";
8+
import { services, LocationServices, LocationConfig } from "../common/coreservices";
9+
import { LocationPlugin, ServicesPlugin } from "./interface";
10+
import { extend } from "../common/common";
11+
import { hashLocationService, hashLocationConfig } from "./hashLocation";
12+
import { pushStateLocationService, pushStateLocationConfig } from "./pushStateLocation";
913
import { $q } from "./$q";
1014
import { $injector } from "./$injector";
11-
import { hashHistory } from "./hashHistory";
12-
import { browserHistory } from "./browserHistory";
13-
import { HistoryImplementationPlugin, ServicesPlugin, HistoryImplementation } from "./interface";
14-
import { extend } from "../common/common";
1515

16-
export { $q, $injector, hashHistory, browserHistory };
16+
export { $q, $injector };
1717

18-
export function services(router: UIRouter): ServicesPlugin {
19-
coreservices.$injector = $injector;
20-
coreservices.$q = $q;
18+
export function servicesPlugin(router: UIRouter): ServicesPlugin {
19+
services.$injector = $injector;
20+
services.$q = $q;
2121

2222
return { name: "vanilla.services", $q, $injector };
2323
}
2424

25-
const HistoryImplementationPluginFactory = (name: string, historyImpl: HistoryImplementation) =>
25+
const locationPluginFactory = (name: string, service: LocationServices, configuration: LocationConfig) =>
2626
(router: UIRouter) => {
27-
const { service, configuration } = historyImpl;
28-
extend(coreservices.location, service);
29-
extend(coreservices.locationConfig, configuration);
30-
27+
extend(services.location, service);
28+
extend(services.locationConfig, configuration);
3129
return { name, service, configuration };
3230
};
3331

34-
export const hashLocation: (router: UIRouter) => HistoryImplementationPlugin =
35-
HistoryImplementationPluginFactory("vanilla.hashBangLocation", hashHistory);
36-
export const pushStateLocation: (router: UIRouter) => HistoryImplementationPlugin =
37-
HistoryImplementationPluginFactory("vanilla.pushStateLocation", browserHistory);
32+
export const hashLocationPlugin: (router: UIRouter) => LocationPlugin =
33+
locationPluginFactory("vanilla.hashBangLocation", hashLocationService, hashLocationConfig);
34+
35+
export const pushStateLocationPlugin: (router: UIRouter) => LocationPlugin =
36+
locationPluginFactory("vanilla.pushStateLocation", pushStateLocationService, pushStateLocationConfig);
3837

src/vanilla/interface.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ import { LocationConfig, LocationServices } from '../common/coreservices';
22
import { UIRouterPlugin } from "../interface";
33
import { $InjectorLike, $QLike } from "../common/module";
44

5-
export interface HistoryImplementation {
5+
export interface LocationPlugin extends UIRouterPlugin {
66
service: LocationServices;
77
configuration: LocationConfig;
88
}
99

10-
export interface HistoryImplementationPlugin extends UIRouterPlugin, HistoryImplementation {
11-
12-
}
13-
1410
export interface ServicesPlugin extends UIRouterPlugin {
1511
$q: $QLike,
1612
$injector: $InjectorLike

src/vanilla/browserHistory.ts renamed to src/vanilla/pushStateLocation.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { services, isDefined } from '../common/module';
22
import { LocationConfig, LocationServices } from '../common/coreservices';
3-
import { HistoryImplementation } from './interface';
43
import { splitQuery, trimHashVal, getParams } from './utils';
54

65
let hashPrefix: string = '';
76
let baseHref: string = '';
87

9-
const locationServiceConfig: LocationConfig = {
8+
export const pushStateLocationConfig: LocationConfig = {
109
port: () =>
1110
parseInt(location.port),
1211
protocol: () =>
@@ -25,7 +24,7 @@ const locationServiceConfig: LocationConfig = {
2524
}
2625
};
2726

28-
const locationService: LocationServices = {
27+
export const pushStateLocationService: LocationServices = {
2928
hash: () =>
3029
trimHashVal(location.hash),
3130
path: () => {
@@ -45,8 +44,3 @@ const locationService: LocationServices = {
4544
},
4645
onChange: (cb: EventListener) => window.addEventListener("popstate", cb, false) as any
4746
};
48-
49-
export const browserHistory: HistoryImplementation = {
50-
service: locationService,
51-
configuration: locationServiceConfig
52-
};

test/hookBuilderSpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('HookBuilder:', function() {
1616
beforeEach(() => {
1717
log = "";
1818
uiRouter = new UIRouter();
19-
uiRouter.plugin(vanilla.services);
20-
uiRouter.plugin(vanilla.hashLocation);
19+
uiRouter.plugin(vanilla.servicesPlugin);
20+
uiRouter.plugin(vanilla.hashLocationPlugin);
2121

2222
$trans = uiRouter.transitionService;
2323
$state = uiRouter.stateService;

test/lazyLoadSpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ describe('future state', function () {
2020

2121
beforeEach(() => {
2222
router = new UIRouter();
23-
router.plugin(vanilla.services);
24-
router.plugin(vanilla.hashLocation);
23+
router.plugin(vanilla.servicesPlugin);
24+
router.plugin(vanilla.hashLocationPlugin);
2525
$registry = router.stateRegistry;
2626
$state = router.stateService;
2727
$transitions = router.transitionService;

test/pluginSpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe('plugin api', function () {
1414

1515
beforeEach(() => {
1616
router = new UIRouter();
17-
router.plugin(vanilla.services);
18-
router.plugin(vanilla.hashLocation);
17+
router.plugin(vanilla.servicesPlugin);
18+
router.plugin(vanilla.hashLocationPlugin);
1919
$registry = router.stateRegistry;
2020
$state = router.stateService;
2121
$transitions = router.transitionService;

test/resolveSpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function getStates() {
6363

6464
beforeEach(function () {
6565
router = new UIRouter();
66-
router.plugin(vanilla.services);
67-
router.plugin(vanilla.hashLocation);
66+
router.plugin(vanilla.servicesPlugin);
67+
router.plugin(vanilla.hashLocationPlugin);
6868
router.stateRegistry.stateQueue.autoFlush(router.stateService);
6969

7070
counts = { _J: 0, _J2: 0, _K: 0, _L: 0, _M: 0, _Q: 0 };

test/stateServiceSpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('stateService', function () {
2828

2929
beforeEach(() => {
3030
router = new UIRouter();
31-
router.plugin(vanilla.services);
32-
router.plugin(vanilla.hashLocation);
31+
router.plugin(vanilla.servicesPlugin);
32+
router.plugin(vanilla.hashLocationPlugin);
3333
$loc = services.location;
3434
$state = router.stateService;
3535
$registry = router.stateRegistry;

test/transitionSpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('transition', function () {
3030

3131
beforeEach(() => {
3232
router = new UIRouter();
33-
router.plugin(vanilla.services);
34-
router.plugin(vanilla.hashLocation);
33+
router.plugin(vanilla.servicesPlugin);
34+
router.plugin(vanilla.hashLocationPlugin);
3535
$state = router.stateService;
3636
$transitions = router.transitionService;
3737
router.stateRegistry.stateQueue.autoFlush($state);

test/vanilla.browserHistorySpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ describe('browserHistory implementation', () => {
1919

2020
beforeEach(() => {
2121
router = new UIRouter();
22-
router.plugin(vanilla.services);
23-
router.plugin(vanilla.pushStateLocation);
22+
router.plugin(vanilla.servicesPlugin);
23+
router.plugin(vanilla.pushStateLocationPlugin);
2424
router.stateRegistry.stateQueue.autoFlush(router.stateService);
2525
makeMatcher = (url, config?) => {
2626
return new UrlMatcher(url, router.urlMatcherFactory.paramTypes, config)

test/vanilla.hashHistorySpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe('hashHistory implementation', () => {
1010

1111
beforeEach(() => {
1212
router = new UIRouter();
13-
router.plugin(vanilla.services);
14-
router.plugin(vanilla.hashLocation);
13+
router.plugin(vanilla.servicesPlugin);
14+
router.plugin(vanilla.hashLocationPlugin);
1515
$state = router.stateService;
1616
router.stateRegistry.stateQueue.autoFlush($state);
1717

0 commit comments

Comments
 (0)