[ember] refactor @ember/routing types into their own package (#28844)

* [ember] failing test - relax ObserverMethod property name arg

* [ember] relax ObserverMethod property name arg

* [ember] @ember/routing types refactored into their own package

* Update index.d.ts
This commit is contained in:
Mike North
2018-09-13 09:52:49 -07:00
committed by Ryan Cavanaugh
parent 2609e62c2d
commit 488594c9b3
15 changed files with 251 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class AutoLocation extends Ember.AutoLocation { }

View File

@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class HashLocation extends Ember.HashLocation { }

View File

@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class HistoryLocation extends Ember.HistoryLocation { }

8
types/ember__routing/index.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
// Type definitions for @ember/routing 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export { default as Route } from '@ember/routing/route';
export { default as Router } from '@ember/routing/router';

View File

@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class LinkComponent extends Ember.LinkComponent { }

4
types/ember__routing/location.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
import Ember from 'ember';
export const Location: typeof Ember.Location;
export default Location;

View File

@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class NoneLocation extends Ember.NoneLocation { }

3
types/ember__routing/route.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class Route extends Ember.Route { }

View File

@@ -0,0 +1,3 @@
import { RouterService } from 'ember';
export default class extends RouterService { }

3
types/ember__routing/router.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class EmberRouter extends Ember.Router { }

View File

@@ -0,0 +1,5 @@
/** Static assertion that `value` has type `T` */
// Disable tslint here b/c the generic is used to let us do a type coercion and
// validate that coercion works for the type value "passed into" the function.
// tslint:disable-next-line:no-unnecessary-generics
export declare function assertType<T>(value: T): T;

View File

@@ -0,0 +1,112 @@
import Route from '@ember/routing/route';
import Array from '@ember/array';
import Ember from 'ember'; // currently needed for Transition
import EmberObject from '@ember/object';
import Controller from '@ember/controller';
class Post extends EmberObject {}
interface Posts extends Array<Post> {}
Route.extend({
beforeModel(transition: Ember.Transition) {
this.transitionTo('someOtherRoute');
},
});
Route.extend({
afterModel(posts: Posts, transition: Ember.Transition) {
if (posts.length === 1) {
this.transitionTo('post.show', posts.firstObject);
}
},
});
Route.extend({
actions: {
showModal(evt: { modalName: string }) {
this.render(evt.modalName, {
outlet: 'modal',
into: 'application',
});
},
hideModal(evt: { modalName: string }) {
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application',
});
},
},
});
Ember.Route.extend({
model() {
return this.modelFor('post');
},
});
Route.extend({
queryParams: {
memberQp: { refreshModel: true },
},
});
Route.extend({
renderTemplate() {
this.render('photos', {
into: 'application',
outlet: 'anOutletName',
});
},
});
Route.extend({
renderTemplate(controller: Ember.Controller, model: {}) {
this.render('posts', {
view: 'someView', // the template to render, referenced by name
into: 'application', // the template to render into, referenced by name
outlet: 'anOutletName', // the outlet inside `options.into` to render into.
controller: 'someControllerName', // the controller to use for this template, referenced by name
model, // the model to set on `options.controller`.
});
},
});
Route.extend({
resetController(controller: Ember.Controller, isExiting: boolean, transition: boolean) {
if (isExiting) {
// controller.set('page', 1);
}
},
});
class ApplicationController extends Controller {}
declare module '@ember/controller' {
interface Registry {
application: ApplicationController;
}
}
Route.extend({
setupController(controller: Controller, model: {}) {
this._super(controller, model);
this.controllerFor('application').set('model', model);
},
});
class RouteUsingClass extends Route.extend({
randomProperty: 'the .extend + extends bit type-checks properly',
}) {
beforeModel(this: RouteUsingClass) {
return 'beforeModel can return anything, not just promises';
}
intermediateTransitionWithoutModel() {
this.intermediateTransitionTo('some-route');
}
intermediateTransitionWithModel() {
this.intermediateTransitionTo('some.other.route', { });
}
intermediateTransitionWithMultiModel() {
this.intermediateTransitionTo('some.other.route', 1, 2, { });
}
}

View File

@@ -0,0 +1,54 @@
import Ember from 'ember';
import { assertType } from './lib/assert';
const AppRouter = Ember.Router.extend({
});
AppRouter.map(function() {
this.route('index', { path: '/' });
this.route('about');
this.route('favorites', { path: '/favs' });
this.route('posts', function() {
this.route('index', { path: '/' });
this.route('new');
this.route('post', { path: '/post/:post_id', resetNamespace: true });
this.route('comments', { resetNamespace: true }, function() {
this.route('new');
});
});
this.route('photo', { path: '/photo/:id' }, function() {
this.route('comment', { path: '/comment/:id' });
});
this.route('not-found', { path: '/*path' });
this.mount('my-engine');
this.mount('my-engine', { as: 'some-other-engine', path: '/some-other-engine'});
});
const RouterServiceConsumer = Ember.Service.extend({
router: Ember.inject.service('router'),
currentRouteName() {
const x: string = Ember.get(this, 'router').currentRouteName;
},
currentURL() {
const x: string = Ember.get(this, 'router').currentURL;
},
transitionWithoutModel() {
Ember.get(this, 'router')
.transitionTo('some-route');
},
transitionWithModel() {
const model = Ember.Object.create();
Ember.get(this, 'router')
.transitionTo('some.other.route', model);
},
transitionWithMultiModel() {
const model = Ember.Object.create();
Ember.get(this, 'router')
.transitionTo('some.other.route', model, model);
},
transitionWithModelAndOptions() {
const model = Ember.Object.create();
Ember.get(this, 'router')
.transitionTo('index', model, { queryParams: { search: 'ember' }});
}
});

View File

@@ -0,0 +1,40 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/routing": ["ember__routing"],
"@ember/routing/*": ["ember__routing/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"auto-location.d.ts",
"hash-location.d.ts",
"history-location.d.ts",
"index.d.ts",
"link-component.d.ts",
"location.d.ts",
"none-location.d.ts",
"route.d.ts",
"router-service.d.ts",
"router.d.ts",
"test/lib/assert.ts",
"test/route.ts",
"test/router.ts"
]
}

View File

@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}