Skip to content

Commit

Permalink
[ember]: refactor @ember/debug into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-north committed Sep 12, 2018
1 parent 5f7be1f commit c9b3a76
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 11 deletions.
25 changes: 14 additions & 11 deletions types/ember/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3637,20 +3637,23 @@ declare module '@ember/controller' {
export interface Registry {}
}

declare module '@ember/debug' {
import Ember from 'ember';
export const assert: typeof Ember.assert;
export const debug: typeof Ember.debug;
export const inspect: typeof Ember.inspect;
export const registerDeprecationHandler: typeof Ember.Debug.registerDeprecationHandler;
export const registerWarnHandler: typeof Ember.Debug.registerWarnHandler;
export const runInDebug: typeof Ember.runInDebug;
export const warn: typeof Ember.warn;
}
// declare module '@ember/debug' {
// import Ember from 'ember';
// export const assert: typeof Ember.assert;
// export const debug: typeof Ember.debug;
// export const inspect: typeof Ember.inspect;
// export const registerDeprecationHandler: typeof Ember.Debug.registerDeprecationHandler;
// export const registerWarnHandler: typeof Ember.Debug.registerWarnHandler;
// export const runInDebug: typeof Ember.runInDebug;
// export const warn: typeof Ember.warn;
// }

declare module '@ember/debug/container-debug-adapter' {
import Ember from 'ember';
export default class ContainerDebugAdapter extends Ember.ContainerDebugAdapter { }
export default class ContainerDebugAdapter extends Ember.ContainerDebugAdapter {
catalogEntriesByType(type: string): string[];
canCatalogEntriesByType(type: string): boolean;
}
}

declare module '@ember/debug/data-adapter' {
Expand Down
2 changes: 2 additions & 0 deletions types/ember__debug/container-debug-adapter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Ember from 'ember';
export default class ContainerDebugAdapter extends Ember.ContainerDebugAdapter { }
3 changes: 3 additions & 0 deletions types/ember__debug/data-adapter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Ember from 'ember';

export default class DataAdapter extends Ember.DataAdapter {}
68 changes: 68 additions & 0 deletions types/ember__debug/ember__debug-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { registerDeprecationHandler, runInDebug, warn, assert, debug, registerWarnHandler } from '@ember/debug';
import ContainerDebugAdapter from '@ember/debug/container-debug-adapter';
import DataAdapter from '@ember/debug/data-adapter';

/**
* @ember/debug tests
*/
runInDebug(); // $ExpectError
let x = runInDebug(() => console.log('Should not show up in prod')); // $ExpectType void

// Log a warning if we have more than 3 tomsters
const tomsterCount = 2;
warn('Too many tomsters!'); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3, { id: 'ember-debug.too-many-tomsters' }); // $ExpectType void

debug(); // $ExpectError
debug('Too many tomsters!'); // $ExpectType void
debug('Too many tomsters!', 'foo'); // $ExpectError

// Test for truthiness
const str = 'hello';
assert('Must pass a string', typeof str === 'string'); // $ExpectType void

// Fail unconditionally
assert('This code path should never be run'); // $ExpectType void

// next is not called, so no warnings get the default behavior
registerWarnHandler(); // $ExpectError
registerWarnHandler(() => {}); // $ExpectType void
registerWarnHandler((message, {id, next}) => { // $ExpectType void
message; // $ExpectType string
id; // $ExpectType string
next; // $ExpectType () => void
});

// next is not called, so no warnings get the default behavior
registerDeprecationHandler(); // $ExpectError
registerDeprecationHandler(() => {}); // $ExpectType void
registerDeprecationHandler((message, {id, next, until}) => { // $ExpectType void
message; // $ExpectType string
id; // $ExpectType string
until; // $ExpectType string
next; // $ExpectType () => void
});

/**
* @ember/debug/data-adapter tests
*/

const da = new DataAdapter(); // $ExpectType DataAdapter
const da2 = DataAdapter.create(); // $ExpectType DataAdapter

da.containerDebugAdapter; // $ExpectType any
da.acceptsModelName; // $ExpectType any
da.getFilters; // $ExpectType () => any[]
da.watchModelTypes(() => ({}), () => ({})); // ExpectType (...args: any[]) => any
da.watchRecords('model:book', () => ({}), () => ({}), () => ({})); // ExpectType (...args: any[]) => any

/**
* @ember/debug/container-debug-adapter tests
*/

const cda = new ContainerDebugAdapter(); // $ExpectType ContainerDebugAdapter
const cda2 = ContainerDebugAdapter.create(); // $ExpectType ContainerDebugAdapter

cda.catalogEntriesByType('service'); // $ExpectType string[]
cda.canCatalogEntriesByType('service'); // $ExpectType boolean
14 changes: 14 additions & 0 deletions types/ember__debug/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Type definitions for @ember/debug 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

import Ember from 'ember';
export const assert: typeof Ember.assert;
export const debug: typeof Ember.debug;
export const inspect: typeof Ember.inspect;
export const registerDeprecationHandler: typeof Ember.Debug.registerDeprecationHandler;
export const registerWarnHandler: typeof Ember.Debug.registerWarnHandler;
export const runInDebug: typeof Ember.runInDebug;
export const warn: typeof Ember.warn;
31 changes: 31 additions & 0 deletions types/ember__debug/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/debug": ["ember__debug"],
"@ember/debug/*": ["ember__debug/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"data-adapter.d.ts",
"container-debug-adapter.d.ts",
"ember__debug-tests.ts"
]
}
30 changes: 30 additions & 0 deletions types/ember__debug/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "dtslint/dt.json",
"rules": {
// Heavy use of Function type in this older package.
"ban-types": false,
"jsdoc-format": false,
"no-misused-new": false,

// these are disabled because of rfc176 module exports
"strict-export-declare-modifiers": false,
"no-single-declare-module": false,
"no-declare-current-package": false,
"no-self-import": false,

// We use interfaces in a number of places to express things (including
// mixins in particular, but also including extending a global
// interface) which TS currently can't express correctly.
"no-empty-interface": false,

"no-duplicate-imports": false,
"no-unnecessary-qualifier": false,
"prefer-const": false,
"no-void-expression": false,
"only-arrow-functions": false,
"no-submodule-imports": false,

// false positives
"unified-signatures": false
}
}

0 comments on commit c9b3a76

Please sign in to comment.