language
stringclasses 1
value | owner
stringlengths 2
15
| repo
stringlengths 2
21
| sha
stringlengths 45
45
| message
stringlengths 7
36.3k
| path
stringlengths 1
199
| patch
stringlengths 15
102k
| is_multipart
bool 2
classes |
---|---|---|---|---|---|---|---|
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/action_support.ts | @@ -5,8 +5,16 @@ import { inspect } from '@ember/-internals/utils';
import { Mixin, get } from '@ember/-internals/metal';
import { assert } from '@ember/debug';
-const mixinObj = {
- send(actionName, ...args) {
+/**
+ @class ActionSupport
+ @namespace Ember
+ @private
+*/
+interface ActionSupport {
+ send(actionName: string, ...args: unknown[]): void;
+}
+const ActionSupport = Mixin.create({
+ send(actionName: string, ...args: unknown[]) {
assert(
`Attempted to call .send() with the action '${actionName}' on the destroyed object '${this}'.`,
!this.isDestroying && !this.isDestroyed
@@ -32,11 +40,6 @@ const mixinObj = {
assert(`${inspect(this)} had no action handler for: ${actionName}`, action);
}
},
-};
+});
-/**
- @class ActionSupport
- @namespace Ember
- @private
-*/
-export default Mixin.create(mixinObj);
+export default ActionSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/child_views_support.d.ts | @@ -1,10 +0,0 @@
-import { View } from '@ember/-internals/glimmer/lib/renderer';
-import Mixin from '@ember/object/mixin';
-
-interface ChildViewsSupport {
- readonly childViews: View[];
- appendChild(view: View): void;
-}
-declare const ChildViewsSupport: Mixin;
-
-export default ChildViewsSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/child_views_support.ts | @@ -1,10 +1,15 @@
/**
@module ember
*/
+import { View } from '@ember/-internals/glimmer/lib/renderer';
import { Mixin, nativeDescDecorator } from '@ember/-internals/metal';
import { getChildViews, addChildView } from '../system/utils';
-export default Mixin.create({
+interface ChildViewsSupport {
+ readonly childViews: View[];
+ appendChild(view: View): void;
+}
+const ChildViewsSupport = Mixin.create({
/**
Array of child views. You should never edit this array directly.
@@ -16,12 +21,14 @@ export default Mixin.create({
childViews: nativeDescDecorator({
configurable: false,
enumerable: false,
- get() {
+ get(this: View) {
return getChildViews(this);
},
}),
- appendChild(view) {
+ appendChild(view: View) {
addChildView(this, view);
},
});
+
+export default ChildViewsSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/class_names_support.d.ts | @@ -1,9 +0,0 @@
-import Mixin from '@ember/object/mixin';
-
-interface ClassNamesSupport {
- classNames: string[];
- classNameBindings: string[];
-}
-declare const ClassNamesSupport: Mixin;
-
-export default ClassNamesSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/class_names_support.ts | @@ -11,7 +11,11 @@ const EMPTY_ARRAY = Object.freeze([]);
@namespace Ember
@private
*/
-export default Mixin.create({
+interface ClassNamesSupport {
+ classNames: string[];
+ classNameBindings: string[];
+}
+const ClassNamesSupport = Mixin.create({
concatenatedProperties: ['classNames', 'classNameBindings'],
init() {
@@ -99,3 +103,5 @@ export default Mixin.create({
*/
classNameBindings: EMPTY_ARRAY,
});
+
+export default ClassNamesSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/view_state_support.d.ts | @@ -1,8 +0,0 @@
-import Mixin from '@ember/object/mixin';
-
-interface ViewStateSupport {
- _transitionTo(state: unknown): void;
-}
-declare const ViewStateSupport: Mixin;
-
-export default ViewStateSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/view_state_support.ts | @@ -2,9 +2,15 @@
@module ember
*/
import { Mixin } from '@ember/-internals/metal';
+import type Component from '@ember/component';
+import type states from '../views/states';
-export default Mixin.create({
- _transitionTo(state) {
+interface ViewStateSupport {
+ /** @internal */
+ _transitionTo(state: keyof typeof states): void;
+}
+const ViewStateSupport = Mixin.create({
+ _transitionTo(this: Component, state: keyof typeof states) {
let priorState = this._currentState;
let currentState = (this._currentState = this._states[state]);
this._state = state;
@@ -17,3 +23,5 @@ export default Mixin.create({
}
},
});
+
+export default ViewStateSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/view_support.d.ts | @@ -1,19 +0,0 @@
-import Mixin from '@ember/object/mixin';
-
-interface ViewSupport {
- rerender(): unknown;
- element: Element;
- appendTo(selector: string | Element): this;
- append(): this;
- elementId: string | null;
- willInsertElement(): void;
- didInsertElement(): void;
- willClearRender(): void;
- willDestroyElement(): void;
- parentViewDidChange(): void;
- tagName: string | null;
- handleEvent(eventName: string, evt: unknown): unknown;
-}
-declare const ViewSupport: Mixin;
-
-export default ViewSupport; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/mixins/view_support.ts | @@ -3,12 +3,34 @@ import { descriptorForProperty, Mixin, nativeDescDecorator } from '@ember/-inter
import { assert } from '@ember/debug';
import { hasDOM } from '@ember/-internals/browser-environment';
import { matches } from '../system/utils';
+import type Component from '@ember/component';
+import { View } from '@ember/-internals/glimmer/lib/renderer';
+import { SimpleElement } from '@simple-dom/interface';
-function K() {
+function K(this: unknown) {
return this;
}
-let mixin = {
+/**
+ @class ViewMixin
+ @namespace Ember
+ @private
+*/
+interface ViewMixin {
+ rerender(): unknown;
+ element: SimpleElement;
+ appendTo(selector: string | Element | SimpleElement): this;
+ append(): this;
+ elementId: string | null;
+ willInsertElement(): void;
+ didInsertElement(): void;
+ willClearRender(): void;
+ willDestroyElement(): void;
+ parentViewDidChange(): void;
+ tagName: string | null;
+ handleEvent(eventName: string, evt: Event): boolean;
+}
+const ViewMixin = Mixin.create({
/**
A list of properties of the view to apply as attributes. If the property
is a string value, the value of that string will be applied as the value
@@ -78,19 +100,21 @@ let mixin = {
@deprecated use `yield` and contextual components for composition instead.
@private
*/
- nearestOfType(klass) {
+ nearestOfType(this: Component, klass: any) {
let view = this.parentView;
let isOfType =
klass instanceof Mixin
- ? (view) => klass.detect(view)
- : (view) => klass.detect(view.constructor);
+ ? (view: View) => klass.detect(view)
+ : (view: View) => klass.detect(view.constructor);
while (view) {
if (isOfType(view)) {
return view;
}
view = view.parentView;
}
+
+ return;
},
/**
@@ -102,7 +126,7 @@ let mixin = {
@deprecated use `yield` and contextual components for composition instead.
@private
*/
- nearestWithProperty(property) {
+ nearestWithProperty(property: string) {
let view = this.parentView;
while (view) {
@@ -148,7 +172,7 @@ let mixin = {
element: nativeDescDecorator({
configurable: false,
enumerable: false,
- get() {
+ get(this: Component) {
return this.renderer.getElement(this);
},
}),
@@ -170,10 +194,15 @@ let mixin = {
@return {Ember.View} receiver
@private
*/
- appendTo(selector) {
+ appendTo(this: Component, selector: string | Element | SimpleElement) {
let target;
if (hasDOM) {
+ assert(
+ `Expected a selector or instance of Element`,
+ typeof selector === 'string' || selector instanceof Element
+ );
+
target = typeof selector === 'string' ? document.querySelector(selector) : selector;
assert(`You tried to append to (${selector}) but that isn't in the DOM`, target);
@@ -182,8 +211,8 @@ let mixin = {
'You cannot append to an existing Ember.View.',
(() => {
let node = target.parentNode;
- while (node) {
- if (node.nodeType !== 9 && matches(node, '.ember-view')) {
+ while (node instanceof Element) {
+ if (matches(node, '.ember-view')) {
return false;
}
@@ -202,11 +231,13 @@ let mixin = {
);
assert(
`You tried to append to a non-Element (${selector}) in an environment without a DOM`,
- typeof selector.appendChild === 'function'
+ typeof target.appendChild === 'function'
);
}
- this.renderer.appendTo(this, target);
+ // SAFETY: SimpleElement is supposed to be a subset of Element so this _should_ be safe.
+ // However, the types are more specific in some places which necessitates the `as`.
+ this.renderer.appendTo(this, target as unknown as SimpleElement);
return this;
},
@@ -412,14 +443,9 @@ let mixin = {
@param evt {Event}
@private
*/
- handleEvent(eventName, evt) {
+ handleEvent(this: Component, eventName: string, evt: Event) {
return this._currentState.handleEvent(this, eventName, evt);
},
-};
+});
-/**
- @class ViewMixin
- @namespace Ember
- @private
-*/
-export default Mixin.create(mixin);
+export default ViewMixin; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/system/action_manager.ts | @@ -1,3 +1,5 @@
+import type { ActionState } from '@ember/-internals/glimmer/lib/modifiers/action';
+
/**
@module ember
*/
@@ -11,4 +13,4 @@ export default function ActionManager() {}
@property registeredActions
@type Object
*/
-ActionManager.registeredActions = {};
+ActionManager.registeredActions = {} as Record<string, ActionState>; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/system/event_dispatcher.d.ts | @@ -1,11 +0,0 @@
-import EmberObject from '@ember/object';
-
-export default class EventDispatcher extends EmberObject {
- finalEventNameMapping: Record<string, string>;
- lazyEvents: Map<string, string>;
- setupHandlerForBrowserEvent(event: string): void;
- setupHandlerForEmberEvent(event: string): void;
-
- /** @private */
- setup(addedEvents: Record<string, string | null>, rootElement: string | Element | null): void;
-} | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/system/event_dispatcher.ts | @@ -4,6 +4,10 @@ import { get, set } from '@ember/-internals/metal';
import { Object as EmberObject } from '@ember/-internals/runtime';
import { getElementView } from '@ember/-internals/views';
import ActionManager from './action_manager';
+import { BootEnvironment } from '@ember/-internals/glimmer/lib/views/outlet';
+import type Component from '@ember/component';
+import { ActionState } from '@ember/-internals/glimmer/lib/modifiers/action';
+import { SimpleElement } from '@simple-dom/interface';
/**
@module ember
@@ -23,7 +27,7 @@ const ROOT_ELEMENT_SELECTOR = `.${ROOT_ELEMENT_CLASS}`;
@private
@extends Ember.Object
*/
-export default EmberObject.extend({
+export default class EventDispatcher extends EmberObject {
/**
The set of events names (and associated handler function names) to be setup
and dispatched by the `EventDispatcher`. Modifications to this list can be done
@@ -57,7 +61,7 @@ export default EmberObject.extend({
@type Object
@private
*/
- events: {
+ events: Record<string, string> = {
touchstart: 'touchStart',
touchmove: 'touchMove',
touchend: 'touchEnd',
@@ -82,7 +86,7 @@ export default EmberObject.extend({
dragover: 'dragOver',
drop: 'drop',
dragend: 'dragEnd',
- },
+ };
/**
The root DOM element to which event listeners should be attached. Event
@@ -98,16 +102,14 @@ export default EmberObject.extend({
@type DOMElement
@default 'body'
*/
- rootElement: 'body',
+ rootElement: string | Element = 'body';
- init() {
- this._super();
- this._eventHandlers = Object.create(null);
- this._didSetup = false;
- this.finalEventNameMapping = null;
- this._sanitizedRootElement = null;
- this.lazyEvents = new Map();
- },
+ _eventHandlers = Object.create(null);
+ _didSetup = false;
+ finalEventNameMapping: Record<string, string> | null = null;
+ _sanitizedRootElement: Element | null = null;
+ lazyEvents: Map<string, string | null> = new Map();
+ _reverseEventNameMapping: Record<string, string> | null = null;
/**
Sets up event listeners for standard browser events.
@@ -121,53 +123,57 @@ export default EmberObject.extend({
@method setup
@param addedEvents {Object}
*/
- setup(addedEvents, _rootElement) {
+ setup(addedEvents: Record<string, string | null>, _rootElement: string | Element | null): void {
assert(
'EventDispatcher should never be setup in fastboot mode. Please report this as an Ember bug.',
(() => {
let owner = getOwner(this);
- let environment = owner.lookup('-environment:main');
+ assert('[BUG] Missing owner', owner);
+
+ // SAFETY: This is not guaranteed to be safe, but this is what we expect to be returned.
+ let environment = owner.lookup('-environment:main') as BootEnvironment;
return environment.isInteractive;
})()
);
- let events = (this.finalEventNameMapping = Object.assign({}, get(this, 'events'), addedEvents));
- this._reverseEventNameMapping = Object.keys(events).reduce(
- (result, key) => Object.assign(result, { [events[key]]: key }),
- {}
- );
+ let events: Record<string, string | null> = (this.finalEventNameMapping = {
+ ...get(this, 'events'),
+ ...addedEvents,
+ });
+ this._reverseEventNameMapping = Object.keys(events).reduce((result, key) => {
+ let eventName = events[key];
+ return eventName ? { ...result, [eventName]: key } : result;
+ }, {});
let lazyEvents = this.lazyEvents;
if (_rootElement !== undefined && _rootElement !== null) {
set(this, 'rootElement', _rootElement);
}
- let rootElementSelector = get(this, 'rootElement');
- let rootElement;
- if (typeof rootElementSelector !== 'string') {
- rootElement = rootElementSelector;
- } else {
- rootElement = document.querySelector(rootElementSelector);
- }
+ let specifiedRootElement = get(this, 'rootElement');
+ let rootElement: Element | null =
+ typeof specifiedRootElement !== 'string'
+ ? specifiedRootElement
+ : document.querySelector(specifiedRootElement);
+
+ assert(`Could not find rootElement (${specifiedRootElement})`, rootElement);
assert(
- `You cannot use the same root element (${
- get(this, 'rootElement') || rootElement.tagName
- }) multiple times in an Ember.Application`,
+ `You cannot use the same root element (${specifiedRootElement}) multiple times in an Ember.Application`,
!rootElement.classList.contains(ROOT_ELEMENT_CLASS)
);
assert(
'You cannot make a new Ember.Application using a root element that is a descendent of an existing Ember.Application',
(() => {
let target = rootElement.parentNode;
- do {
+ while (target instanceof Element) {
if (target.classList.contains(ROOT_ELEMENT_CLASS)) {
return false;
}
target = target.parentNode;
- } while (target && target.nodeType === 1);
+ }
return true;
})()
@@ -192,12 +198,12 @@ export default EmberObject.extend({
// setup event listeners for the non-lazily setup events
for (let event in events) {
if (Object.prototype.hasOwnProperty.call(events, event)) {
- lazyEvents.set(event, events[event]);
+ lazyEvents.set(event, events[event] ?? null);
}
}
this._didSetup = true;
- },
+ }
/**
Setup event listeners for the given browser event name
@@ -206,9 +212,11 @@ export default EmberObject.extend({
@method setupHandlerForBrowserEvent
@param event the name of the event in the browser
*/
- setupHandlerForBrowserEvent(event) {
- this.setupHandler(this._sanitizedRootElement, event, this.finalEventNameMapping[event]);
- },
+ setupHandlerForBrowserEvent(event: string) {
+ assert('[BUG] Expected finalEventNameMapping to be set', this.finalEventNameMapping);
+ assert('[BUG] Expected _santizedRootElement to be set', this._sanitizedRootElement);
+ this.setupHandler(this._sanitizedRootElement, event, this.finalEventNameMapping[event] ?? null);
+ }
/**
Setup event listeners for the given Ember event name (camel case)
@@ -217,13 +225,15 @@ export default EmberObject.extend({
@method setupHandlerForEmberEvent
@param eventName
*/
- setupHandlerForEmberEvent(eventName) {
- this.setupHandler(
- this._sanitizedRootElement,
- this._reverseEventNameMapping[eventName],
- eventName
- );
- },
+ setupHandlerForEmberEvent(eventName: string) {
+ assert('[BUG] Expected _sanitizedRootElement to be set', this._sanitizedRootElement);
+
+ let event = this._reverseEventNameMapping?.[eventName];
+
+ if (event) {
+ this.setupHandler(this._sanitizedRootElement, event, eventName);
+ }
+ }
/**
Registers an event listener on the rootElement. If the given event is
@@ -239,50 +249,58 @@ export default EmberObject.extend({
@param {String} event the name of the event in the browser
@param {String} eventName the name of the method to call on the view
*/
- setupHandler(rootElement, event, eventName) {
+ setupHandler(rootElement: Element, event: string, eventName: string | null) {
if (eventName === null || !this.lazyEvents.has(event)) {
return; // nothing to do
}
- let viewHandler = (target, event) => {
- let view = getElementView(target);
+ let viewHandler = (target: Element, event: Event) => {
+ // SAFETY: SimpleElement is supposed to be a subset of Element so this _should_ be safe.
+ // However, the types are more specific in some places which necessitates the `as`.
+ let view = getElementView(target as unknown as SimpleElement);
let result = true;
if (view) {
- result = view.handleEvent(eventName, event);
+ // SAFETY: As currently written, this is not safe. Though it seems to always be true.
+ result = (view as Component).handleEvent(eventName, event);
}
return result;
};
- let actionHandler = (target, event) => {
+ let actionHandler = (target: Element, event: Event) => {
let actionId = target.getAttribute('data-ember-action');
- let actions = ActionManager.registeredActions[actionId];
+ let actions: Array<ActionState> | undefined;
// In Glimmer2 this attribute is set to an empty string and an additional
// attribute it set for each action on a given element. In this case, the
// attributes need to be read so that a proper set of action handlers can
// be coalesced.
if (actionId === '') {
- let attributes = target.attributes;
- let attributeCount = attributes.length;
-
actions = [];
- for (let i = 0; i < attributeCount; i++) {
- let attr = attributes.item(i);
+ for (let attr of target.attributes) {
let attrName = attr.name;
if (attrName.indexOf('data-ember-action-') === 0) {
- actions = actions.concat(ActionManager.registeredActions[attr.value]);
+ let action = ActionManager.registeredActions[attr.value];
+ assert('[BUG] Missing action', action);
+ actions.push(action);
}
}
+ } else if (actionId) {
+ // FIXME: This branch is never called in tests. Improve tests or remove
+ let actionState = ActionManager.registeredActions[actionId];
+ if (actionState) {
+ actions = [actionState];
+ }
}
// We have to check for actions here since in some cases, jQuery will trigger
// an event on `removeChild` (i.e. focusout) after we've already torn down the
// action handlers for the view.
if (!actions) {
+ // FIXME: This branch is never called in tests. Improve tests or remove
return;
}
@@ -298,11 +316,18 @@ export default EmberObject.extend({
return result;
};
- let handleEvent = (this._eventHandlers[event] = (event) => {
+ let handleEvent = (this._eventHandlers[event] = (event: Event) => {
let target = event.target;
+ assert(
+ `[BUG] Received event without an Element target: ${event.type}, ${target}`,
+ target instanceof Element
+ );
+
do {
- if (getElementView(target)) {
+ // SAFETY: SimpleElement is supposed to be a subset of Element so this _should_ be safe.
+ // However, the types are more specific in some places which necessitates the `as`.
+ if (getElementView(target as unknown as SimpleElement)) {
if (viewHandler(target, event) === false) {
event.preventDefault();
event.stopPropagation();
@@ -320,26 +345,20 @@ export default EmberObject.extend({
}
target = target.parentNode;
- } while (target && target.nodeType === 1);
+ } while (target instanceof Element);
});
rootElement.addEventListener(event, handleEvent);
this.lazyEvents.delete(event);
- },
+ }
destroy() {
if (this._didSetup === false) {
return;
}
- let rootElementSelector = get(this, 'rootElement');
- let rootElement;
- if (rootElementSelector.nodeType) {
- rootElement = rootElementSelector;
- } else {
- rootElement = document.querySelector(rootElementSelector);
- }
+ let rootElement = this._sanitizedRootElement;
if (!rootElement) {
return;
@@ -352,9 +371,9 @@ export default EmberObject.extend({
rootElement.classList.remove(ROOT_ELEMENT_CLASS);
return this._super(...arguments);
- },
+ }
toString() {
return '(EventDispatcher)';
- },
-});
+ }
+} | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/views/core_view.ts | @@ -1,7 +1,7 @@
import { Renderer, View } from '@ember/-internals/glimmer/lib/renderer';
import { inject } from '@ember/-internals/metal';
import { ActionHandler, Evented, FrameworkObject } from '@ember/-internals/runtime';
-import states from './states';
+import states, { ViewState } from './states';
/**
`Ember.CoreView` is an abstract class that exists to give view-like behavior
@@ -26,8 +26,8 @@ class CoreView extends FrameworkObject.extend(Evented, ActionHandler) {
declare _states: typeof states;
- _state: unknown;
- _currentState: unknown;
+ declare _state: keyof typeof states;
+ declare _currentState: ViewState;
_superTrigger?: Evented['trigger'];
_superHas?: Evented['has']; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/-internals/views/lib/views/states.ts | @@ -6,6 +6,7 @@ import Component from '@ember/component';
export interface ViewState {
enter?(view: Component): void;
+ exit?(view: Component): void;
appendChild(): void;
handleEvent(view: Component, eventName: string, event: Event): boolean;
rerender(view: Component): void; | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/application/instance.ts | @@ -12,12 +12,13 @@ import { assert } from '@ember/debug';
import { Router } from '@ember/-internals/routing';
import { EventDispatcher, ViewMixin } from '@ember/-internals/views';
import { Registry } from '@ember/-internals/container';
+import { SimpleElement } from '@simple-dom/interface';
export interface BootOptions {
isBrowser?: boolean;
shouldRender?: boolean;
document?: Document | null;
- rootElement?: string | Element | null;
+ rootElement?: string | SimpleElement | null;
location?: string | null;
// Private?
isInteractive?: boolean;
@@ -65,7 +66,9 @@ class ApplicationInstance extends EngineInstance {
@private
@property {String|DOMElement} rootElement
*/
- rootElement: string | Element | null = null;
+ rootElement: string | Element | SimpleElement | null = null;
+
+ declare customEvents: Record<string, string | null> | null;
init(properties: object | undefined) {
super.init(properties);
@@ -214,6 +217,12 @@ class ApplicationInstance extends EngineInstance {
let instanceCustomEvents = get(this, 'customEvents');
let customEvents = Object.assign({}, applicationCustomEvents, instanceCustomEvents);
+ assert(
+ '[BUG] Tried to set up dispatcher with an invalid root element',
+ this.rootElement === null ||
+ typeof this.rootElement === 'string' ||
+ this.rootElement instanceof Element
+ );
dispatcher.setup(customEvents, this.rootElement);
return dispatcher;
@@ -447,7 +456,7 @@ class _BootOptions {
@default null
@public
*/
- readonly rootElement?: string | Element;
+ readonly rootElement?: string | SimpleElement;
constructor(options: BootOptions = {}) {
this.isInteractive = Boolean(environment.hasDOM); // This default is overridable below | true |
Other | emberjs | ember.js | 9fb35c41563d450293d991d313bd99f82b4acece.json | Convert view internals to TS | packages/@ember/application/lib/application.ts | @@ -27,6 +27,7 @@ import { Container, privatize as P, Registry } from '@ember/-internals/container
import { setupApplicationRegistry } from '@ember/-internals/glimmer';
import { RouterService } from '@ember/-internals/routing';
import { EngineInstanceOptions } from '@ember/engine/instance';
+import { SimpleDocument, SimpleElement } from '@simple-dom/interface';
/**
An instance of `Application` is the starting point for every Ember
@@ -230,7 +231,7 @@ class Application extends Engine {
@default 'body'
@public
*/
- declare rootElement: Element | string;
+ declare rootElement: SimpleElement | Element | string;
/**
@@ -239,7 +240,7 @@ class Application extends Engine {
@default 'window.document'
@private
*/
- declare _document: Document | null;
+ declare _document: SimpleDocument | Document | null;
/**
The `Ember.EventDispatcher` responsible for delegating events to this
@@ -532,9 +533,20 @@ class Application extends Engine {
waitForDOMReady(): void {
const document = this._document;
- if (document === null || document.readyState !== 'loading') {
+ // SAFETY: Casting as Document should be safe since we're just reading a property.
+ // If it's not actually a Document then it will evaluate false which is fine for our
+ // purposes.
+ if (document === null || (document as Document).readyState !== 'loading') {
schedule('actions', this, this.domReady);
} else {
+ // Ideally we'd just check `document instanceof Document` but currently some tests pass a fake document.
+ assert(
+ '[BUG] Called waitForDOMReady with an invalid document',
+ (function (d: SimpleDocument | Document): d is Document {
+ return typeof (d as Document).removeEventListener === 'function';
+ })(document)
+ );
+
let callback = () => {
document.removeEventListener('DOMContentLoaded', callback);
run(this, this.domReady); | true |
Other | emberjs | ember.js | 9e82676a46db9aca32e7d130aca249f19f2bf4f5.json | Add notes about IContainer and IRegistry | packages/@ember/-internals/runtime/lib/mixins/container_proxy.ts | @@ -7,6 +7,8 @@ import { TypeOptions } from '@ember/-internals/container/lib/registry';
import { Mixin } from '@ember/-internals/metal';
import { Factory } from '@ember/-internals/owner';
+// This is defined as a separate interface so that it can be used in the definition of
+// `Owner` without also including the `__container__` property.
export interface IContainer {
ownerInjection(): void;
lookup(fullName: string, options?: TypeOptions): Factory<object> | object | undefined; | true |
Other | emberjs | ember.js | 9e82676a46db9aca32e7d130aca249f19f2bf4f5.json | Add notes about IContainer and IRegistry | packages/@ember/-internals/runtime/lib/mixins/registry_proxy.ts | @@ -9,6 +9,8 @@ import { Factory } from '@ember/-internals/owner';
import { AnyFn } from '@ember/-internals/utils/types';
import { assert } from '@ember/debug';
+// This is defined as a separate interface so that it can be used in the definition of
+// `Owner` without also including the `__registry__` property.
export interface IRegistry {
resolveRegistration(fullName: string): Factory<object> | object | undefined;
| true |
Other | emberjs | ember.js | 6123eeb93b24c44aaa8b18eff6ea6e6542a44d06.json | Convert ViewStates to TS | packages/@ember/-internals/views/lib/views/states.ts | @@ -2,6 +2,15 @@ import preRender from './states/pre_render';
import hasElement from './states/has_element';
import inDOM from './states/in_dom';
import destroying from './states/destroying';
+import Component from '@ember/component';
+
+export interface ViewState {
+ enter?(view: Component): void;
+ appendChild(): void;
+ handleEvent(view: Component, eventName: string, event: Event): boolean;
+ rerender(view: Component): void;
+ destroy(view: Component): void;
+}
/*
Describe how the specified actions should behave in the various | true |
Other | emberjs | ember.js | 6123eeb93b24c44aaa8b18eff6ea6e6542a44d06.json | Convert ViewStates to TS | packages/@ember/-internals/views/lib/views/states/default.ts | @@ -1,6 +1,7 @@
import EmberError from '@ember/error';
+import type { ViewState } from '../states';
-const _default = {
+const _default: ViewState = {
// appendChild is only legal while rendering the buffer.
appendChild() {
throw new EmberError("You can't use appendChild outside of the rendering process"); | true |
Other | emberjs | ember.js | 6123eeb93b24c44aaa8b18eff6ea6e6542a44d06.json | Convert ViewStates to TS | packages/@ember/-internals/views/lib/views/states/destroying.ts | @@ -1,13 +1,17 @@
import EmberError from '@ember/error';
+import type { ViewState } from '../states';
import _default from './default';
-const destroying = Object.assign({}, _default, {
+const destroying: ViewState = {
+ ..._default,
+
appendChild() {
throw new EmberError("You can't call appendChild on a view being destroyed");
},
+
rerender() {
throw new EmberError("You can't call rerender on a view being destroyed");
},
-});
+};
export default Object.freeze(destroying); | true |
Other | emberjs | ember.js | 6123eeb93b24c44aaa8b18eff6ea6e6542a44d06.json | Convert ViewStates to TS | packages/@ember/-internals/views/lib/views/states/has_element.ts | @@ -1,18 +1,22 @@
import _default from './default';
import { join } from '@ember/runloop';
import { flaggedInstrument } from '@ember/instrumentation';
+import Component from '@ember/component';
+import type { ViewState } from '../states';
-const hasElement = Object.assign({}, _default, {
- rerender(view) {
- view.renderer.rerender(view);
+const hasElement: ViewState = {
+ ..._default,
+
+ rerender(view: Component) {
+ view.renderer.rerender();
},
- destroy(view) {
+ destroy(view: Component) {
view.renderer.remove(view);
},
// Handle events from `Ember.EventDispatcher`
- handleEvent(view, eventName, event) {
+ handleEvent(view: Component, eventName: string, event: Event) {
if (view.has(eventName)) {
// Handler should be able to re-dispatch events, so we don't
// preventDefault or stopPropagation.
@@ -23,6 +27,6 @@ const hasElement = Object.assign({}, _default, {
return true; // continue event propagation
}
},
-});
+};
export default Object.freeze(hasElement); | true |
Other | emberjs | ember.js | 6123eeb93b24c44aaa8b18eff6ea6e6542a44d06.json | Convert ViewStates to TS | packages/@ember/-internals/views/lib/views/states/in_dom.ts | @@ -1,17 +1,26 @@
import { teardownMandatorySetter } from '@ember/-internals/utils';
+import type Component from '@ember/component';
+import { assert } from '@ember/debug';
import EmberError from '@ember/error';
import { DEBUG } from '@glimmer/env';
+import type { ViewState } from '../states';
import hasElement from './has_element';
-const inDOM = Object.assign({}, hasElement, {
- enter(view) {
+const inDOM: ViewState = {
+ ...hasElement,
+
+ enter(view: Component) {
// Register the view for event handling. This hash is used by
// Ember.EventDispatcher to dispatch incoming events.
view.renderer.register(view);
if (DEBUG) {
let elementId = view.elementId;
+ assert(
+ '[BUG] Expected teardownMandatorySetter to be set in DEBUG mode',
+ teardownMandatorySetter
+ );
teardownMandatorySetter(view, 'elementId');
Object.defineProperty(view, 'elementId', {
@@ -29,6 +38,6 @@ const inDOM = Object.assign({}, hasElement, {
});
}
},
-});
+};
export default Object.freeze(inDOM); | true |
Other | emberjs | ember.js | 6123eeb93b24c44aaa8b18eff6ea6e6542a44d06.json | Convert ViewStates to TS | packages/@ember/-internals/views/lib/views/states/pre_render.ts | @@ -1,5 +1,5 @@
import _default from './default';
-const preRender = Object.assign({}, _default);
+const preRender = { ..._default };
export default Object.freeze(preRender); | true |
Other | emberjs | ember.js | 8c9004ece9eed44398a06489dfb561d23710b37d.json | Convert ObjectProxy to TS | packages/@ember/-internals/runtime/lib/system/object_proxy.d.ts | @@ -1,8 +0,0 @@
-import FrameworkObject from './object';
-import _ProxyMixin from '../mixins/-proxy';
-
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-interface ObjectProxy extends _ProxyMixin {}
-declare class ObjectProxy extends FrameworkObject {}
-
-export default ObjectProxy; | true |
Other | emberjs | ember.js | 8c9004ece9eed44398a06489dfb561d23710b37d.json | Convert ObjectProxy to TS | packages/@ember/-internals/runtime/lib/system/object_proxy.ts | @@ -77,5 +77,9 @@ import _ProxyMixin from '../mixins/-proxy';
@uses Ember.ProxyMixin
@public
*/
-export default class ObjectProxy extends FrameworkObject {}
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+interface ObjectProxy extends _ProxyMixin {}
+class ObjectProxy extends FrameworkObject {}
ObjectProxy.PrototypeMixin.reopen(_ProxyMixin);
+
+export default ObjectProxy; | true |
Other | emberjs | ember.js | e0eb44fc655d2f37078b1924c54c14a619efd8b3.json | Eliminate an unnecessary cast in resolver.ts | packages/@ember/-internals/glimmer/lib/resolver.ts | @@ -103,7 +103,7 @@ function lookupComponentPair(
}
}
-const BUILTIN_KEYWORD_HELPERS = {
+const BUILTIN_KEYWORD_HELPERS: Record<string, object> = {
action,
mut,
readonly,
@@ -145,7 +145,7 @@ if (EMBER_UNIQUE_ID_HELPER) {
BUILTIN_HELPERS['unique-id'] = uniqueId;
}
-const BUILTIN_KEYWORD_MODIFIERS = {
+const BUILTIN_KEYWORD_MODIFIERS: Record<string, ModifierDefinitionState> = {
action: actionModifier,
};
@@ -209,7 +209,7 @@ export default class ResolverImpl implements RuntimeResolver<Owner>, CompileTime
}
lookupBuiltInHelper(name: string): HelperDefinitionState | null {
- return (BUILTIN_KEYWORD_HELPERS as Record<string, object>)[name] ?? null;
+ return BUILTIN_KEYWORD_HELPERS[name] ?? null;
}
lookupModifier(name: string, owner: Owner): Option<ModifierDefinitionState> {
@@ -233,7 +233,7 @@ export default class ResolverImpl implements RuntimeResolver<Owner>, CompileTime
): typeof BUILTIN_KEYWORD_MODIFIERS[K];
lookupBuiltInModifier(name: string): null;
lookupBuiltInModifier(name: string): ModifierDefinitionState | null {
- return (BUILTIN_KEYWORD_MODIFIERS as Record<string, ModifierDefinitionState>)[name] ?? null;
+ return BUILTIN_KEYWORD_MODIFIERS[name] ?? null;
}
lookupComponent(name: string, owner: Owner): ResolvedComponentDefinition | null { | false |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/glimmer/lib/helpers/action.ts | @@ -2,6 +2,7 @@
@module ember
*/
import { get } from '@ember/-internals/metal';
+import { AnyFn } from '@ember/-internals/utils/types';
import { assert } from '@ember/debug';
import { flaggedInstrument } from '@ember/instrumentation';
import { join } from '@ember/runloop';
@@ -354,7 +355,7 @@ function makeArgsProcessor(valuePathRef: Reference | false, actionArgsRef: Refer
function makeDynamicClosureAction(
context: object,
targetRef: Reference<MaybeActionHandler>,
- actionRef: Reference<string | ((...args: any[]) => any)>,
+ actionRef: Reference<string | AnyFn>,
processArgs: (args: unknown[]) => unknown[],
debugKey: string
) {
@@ -381,18 +382,18 @@ function makeDynamicClosureAction(
}
interface MaybeActionHandler {
- actions?: Record<string, (...args: any[]) => any>;
+ actions?: Record<string, AnyFn>;
}
function makeClosureAction(
context: object,
target: MaybeActionHandler,
- action: string | ((...args: any[]) => any),
+ action: string | AnyFn,
processArgs: (args: unknown[]) => unknown[],
debugKey: string
) {
let self: object;
- let fn: (...args: any[]) => any;
+ let fn: AnyFn;
assert(
`Action passed is null or undefined in (action) from ${target}.`, | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/metal/lib/events.ts | @@ -3,6 +3,7 @@
*/
import { Meta, meta as metaFor, peekMeta } from '@ember/-internals/meta';
import { setListeners } from '@ember/-internals/utils';
+import { AnyFn } from '@ember/-internals/utils/types';
import { assert } from '@ember/debug';
/*
@@ -203,9 +204,7 @@ export function hasListeners(obj: object, eventName: string): boolean {
@return {Function} the listener function, passed as last argument to on(...)
@public
*/
-export function on<T extends (...args: any[]) => any>(
- ...args: [...eventNames: string[], func: T]
-): T {
+export function on<T extends AnyFn>(...args: [...eventNames: string[], func: T]): T {
let func = args.pop();
let events = args as string[];
| true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/metal/lib/mixin.ts | @@ -12,6 +12,7 @@ import {
setObservers,
wrap,
} from '@ember/-internals/utils';
+import { AnyFn } from '@ember/-internals/utils/types';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { _WeakSet } from '@glimmer/util';
@@ -763,7 +764,7 @@ function _keys(mixin: Mixin, ret = new Set(), seen = new Set()) {
// OBSERVER HELPER
//
-type ObserverDefinition<T extends (...args: any[]) => any> = {
+type ObserverDefinition<T extends AnyFn> = {
dependentKeys: string[];
fn: T;
sync: boolean;
@@ -794,7 +795,7 @@ type ObserverDefinition<T extends (...args: any[]) => any> = {
@public
@static
*/
-export function observer<T extends (...args: any[]) => any>(
+export function observer<T extends AnyFn>(
...args:
| [propertyName: string, ...additionalPropertyNames: string[], func: T]
| [ObserverDefinition<T>] | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/routing/lib/location/auto_location.ts | @@ -2,6 +2,7 @@ import { history, location, userAgent, window } from '@ember/-internals/browser-
import { set } from '@ember/-internals/metal';
import { getOwner } from '@ember/-internals/owner';
import { Object as EmberObject } from '@ember/-internals/runtime';
+import { AnyFn, MethodNamesOf } from '@ember/-internals/utils/types';
import { assert } from '@ember/debug';
import { EmberLocation, UpdateCallback } from './api';
import {
@@ -219,12 +220,6 @@ AutoLocation.reopen({
cancelRouterSetup: false,
});
-type AnyFn = (...args: any[]) => any;
-
-type MethodNamesOf<T> = {
- [K in keyof T]: T[K] extends AnyFn ? K : never;
-}[keyof T];
-
function delegateToConcreteImplementation<N extends MethodNamesOf<Required<EmberLocation>>>(
methodName: N
) { | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/routing/lib/system/route.ts | @@ -21,6 +21,7 @@ import {
typeOf,
} from '@ember/-internals/runtime';
import { isProxy, lookupDescriptor } from '@ember/-internals/utils';
+import { AnyFn } from '@ember/-internals/utils/types';
import Controller from '@ember/controller';
import { ControllerQueryParamType } from '@ember/controller/lib/controller_mixin';
import { assert, info, isTesting } from '@ember/debug';
@@ -71,8 +72,8 @@ type RouteTransitionState<R extends Route> = TransitionState<R> & {
queryParamsFor?: Record<string, Record<string, unknown>>;
};
-type MaybeParameters<T> = T extends (...args: any[]) => any ? Parameters<T> : unknown[];
-type MaybeReturnType<T> = T extends (...args: any[]) => any ? ReturnType<T> : unknown;
+type MaybeParameters<T> = T extends AnyFn ? Parameters<T> : unknown[];
+type MaybeReturnType<T> = T extends AnyFn ? ReturnType<T> : unknown;
export const ROUTE_CONNECTIONS = new WeakMap();
const RENDER = Symbol('render');
@@ -2015,7 +2016,7 @@ class Route<T = unknown>
}
// Set in reopen
- declare actions: Record<string, (...args: any[]) => any>;
+ declare actions: Record<string, AnyFn>;
/**
Sends an action to the router, which will delegate it to the currently | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/routing/lib/system/router.ts | @@ -48,14 +48,7 @@ import type { Timer } from 'backburner';
import { EngineRouteInfo } from './engines';
import EngineInstance from '@ember/engine/instance';
import { QueryParams } from 'route-recognizer';
-
-type AnyFn = (...args: any[]) => any;
-
-type MethodNamesOf<T> = {
- [K in keyof T]: T[K] extends AnyFn ? K : never;
-}[keyof T];
-
-type OmitFirst<F> = F extends [any, ...infer R] ? R : [];
+import { AnyFn, MethodNamesOf, OmitFirst } from '@ember/-internals/utils/types';
function defaultDidTransition<R extends Route>(
this: EmberRouter<R>, | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/runtime/lib/mixins/array.d.ts | @@ -1,4 +1,5 @@
import { Mixin } from '@ember/-internals/metal';
+import { AnyFn } from '@ember/-internals/utils/types';
import Enumerable from './enumerable';
import MutableEnumerable from './mutable_enumerable';
@@ -55,8 +56,8 @@ interface EmberArray<T> extends Enumerable {
): V;
invoke<K extends string>(
methodName: K,
- ...args: Value<T, K> extends (...args: any[]) => any ? Parameters<Value<T, K>> : unknown[]
- ): NativeArray<Value<T, K> extends (...args: any[]) => any ? ReturnType<Value<T, K>> : unknown>;
+ ...args: Value<T, K> extends AnyFn ? Parameters<Value<T, K>> : unknown[]
+ ): NativeArray<Value<T, K> extends AnyFn ? ReturnType<Value<T, K>> : unknown>;
toArray(): T[];
compact(): NativeArray<Exclude<T, null>>;
includes(object: T, startAt?: number): boolean; | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/-internals/utils/types.ts | @@ -0,0 +1,7 @@
+export type AnyFn = (...args: any[]) => any;
+
+export type MethodNamesOf<T> = {
+ [K in keyof T]: T[K] extends AnyFn ? K : never;
+}[keyof T];
+
+export type OmitFirst<F> = F extends [any, ...infer R] ? R : []; | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/debug/index.ts | @@ -1,4 +1,5 @@
import { isChrome, isFirefox } from '@ember/-internals/browser-environment';
+import { AnyFn } from '@ember/-internals/utils/types';
import EmberError from '@ember/error';
import { DEBUG } from '@glimmer/env';
import _deprecate, { DeprecateFunc, DeprecationOptions } from './lib/deprecate';
@@ -243,7 +244,7 @@ if (DEBUG) {
*/
setDebugFunction('deprecateFunc', function deprecateFunc(...args: any[]) {
if (args.length === 3) {
- let [message, options, func] = args as [string, DeprecationOptions, (...args: any[]) => any];
+ let [message, options, func] = args as [string, DeprecationOptions, AnyFn];
return function (this: any, ...args: any[]) {
deprecate(message, false, options);
return func.apply(this, args); | true |
Other | emberjs | ember.js | 7987f54f1fcb91628ddf3e572e6f78ed185ef933.json | Add type utils | packages/@ember/runloop/index.ts | @@ -2,6 +2,7 @@ import { assert } from '@ember/debug';
import { onErrorTarget } from '@ember/-internals/error-handling';
import { flushAsyncObservers } from '@ember/-internals/metal';
import Backburner, { DeferredActionQueues, Timer } from 'backburner';
+import { AnyFn } from '@ember/-internals/utils/types';
export { Timer };
@@ -129,10 +130,7 @@ export const _backburner = new Backburner(_queues, {
@public
*/
export function run<F extends () => any>(method: F): ReturnType<F>;
-export function run<F extends (...args: any[]) => any>(
- method: F,
- ...args: Parameters<F>
-): ReturnType<F>;
+export function run<F extends AnyFn>(method: F, ...args: Parameters<F>): ReturnType<F>;
export function run<T, F extends (this: T, ...args: any[]) => any>(
target: T,
method: F,
@@ -141,8 +139,8 @@ export function run<T, F extends (this: T, ...args: any[]) => any>(
export function run<T, U extends keyof T>(
target: T,
method: U,
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : []
-): T[U] extends (...args: any[]) => any ? ReturnType<T[U]> : unknown;
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : []
+): T[U] extends AnyFn ? ReturnType<T[U]> : unknown;
export function run(...args: any[]): unknown {
// @ts-expect-error TS doesn't like our spread args
return _backburner.run(...args);
@@ -192,10 +190,7 @@ export function run(...args: any[]): unknown {
when called within an existing loop, no return value is possible.
@public
*/
-export function join<F extends (...args: any[]) => any>(
- method: F,
- ...args: Parameters<F>
-): ReturnType<F> | void;
+export function join<F extends AnyFn>(method: F, ...args: Parameters<F>): ReturnType<F> | void;
export function join<T, F extends (this: T, ...args: any[]) => any>(
target: T,
method: F,
@@ -204,8 +199,8 @@ export function join<T, F extends (this: T, ...args: any[]) => any>(
export function join<T, U extends keyof T>(
target: T,
method: U,
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : []
-): T[U] extends (...args: any[]) => any ? ReturnType<T[U]> | void : void;
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : []
+): T[U] extends AnyFn ? ReturnType<T[U]> | void : void;
export function join(methodOrTarget: any, methodOrArg?: any, ...additionalArgs: any[]): any {
return _backburner.join(methodOrTarget, methodOrArg, ...additionalArgs);
}
@@ -281,19 +276,19 @@ export function bind<
method: F,
...args: A
): (...args: RemainingParams<A, Parameters<F>>) => ReturnType<F> | void;
-export function bind<F extends (...args: any[]) => any, A extends PartialParams<Parameters<F>>>(
+export function bind<F extends AnyFn, A extends PartialParams<Parameters<F>>>(
method: F,
...args: A
): (...args: RemainingParams<A, Parameters<F>>) => ReturnType<F> | void;
export function bind<
T,
U extends keyof T,
- A extends T[U] extends (...args: any[]) => any ? PartialParams<Parameters<T[U]>> : []
+ A extends T[U] extends AnyFn ? PartialParams<Parameters<T[U]>> : []
>(
target: T,
method: U,
...args: A
-): T[U] extends (...args: any[]) => any
+): T[U] extends AnyFn
? (...args: RemainingParams<A, Parameters<T[U]>>) => ReturnType<T[U]> | void
: never;
export function bind(...curried: any[]): any {
@@ -411,7 +406,7 @@ export function end() {
@return {*} Timer information for use in canceling, see `cancel`.
@public
*/
-export function schedule<F extends (...args: any[]) => any>(
+export function schedule<F extends AnyFn>(
queueName: string,
method: F,
...args: Parameters<F>
@@ -426,7 +421,7 @@ export function schedule<T, U extends keyof T>(
queueName: string,
target: T,
method: U,
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : []
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : []
): Timer;
export function schedule(...args: any[]): Timer {
// @ts-expect-error TS doesn't like the rest args here
@@ -478,17 +473,14 @@ export function later<T, F extends (this: T, ...args: any[]) => any>(
method: F,
...args: [...args: Parameters<F>, wait: string | number]
): Timer;
-export function later<F extends (...args: any[]) => any>(
+export function later<F extends AnyFn>(
method: F,
...args: [...args: Parameters<F>, wait: string | number]
): Timer;
export function later<T, U extends keyof T>(
target: T,
method: U,
- ...args: [
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : [],
- wait: string | number
- ]
+ ...args: [...args: T[U] extends AnyFn ? Parameters<T[U]> : [], wait: string | number]
): Timer;
export function later(...args: any): Timer {
return _backburner.later(...args);
@@ -509,7 +501,7 @@ export function later(...args: any): Timer {
@return {Object} Timer information for use in canceling, see `cancel`.
@public
*/
-export function once<F extends (...args: any[]) => any>(method: F, ...args: Parameters<F>): Timer;
+export function once<F extends AnyFn>(method: F, ...args: Parameters<F>): Timer;
export function once<T, F extends (this: T, ...args: any[]) => any>(
target: T,
method: F,
@@ -518,7 +510,7 @@ export function once<T, F extends (this: T, ...args: any[]) => any>(
export function once<T, U extends keyof T>(
target: T,
method: U,
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : []
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : []
): Timer;
export function once(...args: any[]): Timer {
// @ts-expect-error TS doesn't like the rest args here
@@ -597,7 +589,7 @@ export function once(...args: any[]): Timer {
@return {Object} Timer information for use in canceling, see `cancel`.
@public
*/
-export function scheduleOnce<F extends (...args: any[]) => any>(
+export function scheduleOnce<F extends AnyFn>(
queueName: string,
method: F,
...args: Parameters<F>
@@ -612,7 +604,7 @@ export function scheduleOnce<T, U extends keyof T>(
queueName: string,
target: T,
method: U,
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : []
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : []
): Timer;
export function scheduleOnce(...args: any[]): Timer {
// @ts-expect-error TS doesn't like the rest args here
@@ -689,7 +681,7 @@ export function scheduleOnce(...args: any[]): Timer {
@return {Object} Timer information for use in canceling, see `cancel`.
@public
*/
-export function next<F extends (...args: any[]) => any>(method: F, ...args: Parameters<F>): Timer;
+export function next<F extends AnyFn>(method: F, ...args: Parameters<F>): Timer;
export function next<T, F extends (this: T, ...args: any[]) => any>(
target: T,
method: F,
@@ -698,7 +690,7 @@ export function next<T, F extends (this: T, ...args: any[]) => any>(
export function next<T, U extends keyof T>(
target: T,
method: U,
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : []
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : []
): Timer;
export function next(...args: any[]) {
return _backburner.later(...args, 1);
@@ -849,7 +841,7 @@ export function cancel(timer: Timer): boolean {
@return {Array} Timer information for use in canceling, see `cancel`.
@public
*/
-export function debounce<F extends (...args: any[]) => any>(
+export function debounce<F extends AnyFn>(
method: F,
...args: [...args: Parameters<F>, wait: string | number, immediate?: boolean]
): Timer;
@@ -862,7 +854,7 @@ export function debounce<T, U extends keyof T>(
target: T,
method: U,
...args: [
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : [],
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : [],
wait: string | number,
immediate?: boolean
]
@@ -915,7 +907,7 @@ export function debounce(...args: any[]) {
@return {Array} Timer information for use in canceling, see `cancel`.
@public
*/
-export function throttle<F extends (...args: any[]) => any>(
+export function throttle<F extends AnyFn>(
method: F,
...args: [...args: Parameters<F>, wait?: string | number, immediate?: boolean]
): Timer;
@@ -928,7 +920,7 @@ export function throttle<T, U extends keyof T>(
target: T,
method: U,
...args: [
- ...args: T[U] extends (...args: any[]) => any ? Parameters<T[U]> : [],
+ ...args: T[U] extends AnyFn ? Parameters<T[U]> : [],
wait?: string | number,
immediate?: boolean
] | true |
Other | emberjs | ember.js | 6c259fcafa2de6fae3810a6761d04a847f5bd49a.json | Add v3.28.9 to CHANGELOG
(cherry picked from commit 40c1849d2230519428c199d2a9b10bf3a3ebf9a6) | CHANGELOG.md | @@ -1,4 +1,8 @@
-# Ember Changelog
+# Ember Changelo
+
+## v3.28.9 (April 19, 2022)
+
+- [#20028](https://github.com/emberjs/ember.js/pull/20028) Fix a memory leak in the Router Service class
### v4.4.0-beta.1 (March 24, 2022)
| false |
Other | emberjs | ember.js | 97aa2436b08e7569e4f6d4e8e692e32dc1d0e909.json | Add v4.4.0-beta.1 to CHANGELOG | CHANGELOG.md | @@ -1,5 +1,13 @@
# Ember Changelog
+### v4.4.0-beta.1 (March 24, 2022)
+
+- [#19882](https://github.com/emberjs/ember.js/pull/19882) / [#20005](https://github.com/emberjs/ember.js/pull/20005) [FEATURE] Implement the `unique-id` helper per [RFC #0659](https://github.com/emberjs/rfcs/blob/master/text/0659-unique-id-helper.md).
+- [#19981](https://github.com/emberjs/ember.js/pull/19981) [FEATURE] Facilitate custom test setups per [RFC #0637](https://github.com/emberjs/rfcs/blob/master/text/0637-customizable-test-setups.md).
+- [#16879](https://github.com/emberjs/ember.js/pull/16879) [BUGFIX] isEmpty on nested objects
+- [#17978](https://github.com/emberjs/ember.js/pull/17978) Make hasListeners public
+- [#20014](https://github.com/emberjs/ember.js/pull/20014) Log `until` for deprecations
+
### v4.3.0 (March 21, 2022)
- [#20025](https://github.com/emberjs/ember.js/pull/20025) [BUGFIX] Fix a memory leak in the Router Service class | false |
Other | emberjs | ember.js | 0e2f7e26384eea39bda21111b24b511ee8444525.json | Add v4.3.0 to CHANGELOG | CHANGELOG.md | @@ -1,12 +1,10 @@
# Ember Changelog
-### v4.3.0-beta.2 (March 1, 2022)
+### v4.3.0 (March 21, 2022)
+- [#20025](https://github.com/emberjs/ember.js/pull/20025) [BUGFIX] Fix a memory leak in the Router Service class
- [#19971](https://github.com/emberjs/ember.js/pull/19971) [BUGFIX] Don't serialize default Query Params on RouterService
-
-### v4.3.0-beta.1 (February 7, 2022)
-
-No public API changes or bugfixes.
+- [#20024](https://github.com/emberjs/ember.js/pull/20024) [BUGFIX] Correctly associate props with factory and owner in FactoryManager
### v4.2.0 (February 7, 2022)
| false |
Other | emberjs | ember.js | 70058439456e66d659465b481c7d282084418940.json | Resolve some issues in TS conversion | packages/@ember/-internals/glimmer/lib/helper.ts | @@ -35,14 +35,6 @@ export interface HelperInstance<T = unknown> {
destroy(): void;
}
-export function isHelperInstance(obj: unknown): obj is HelperInstance {
- if (obj !== null && typeof obj === 'object') {
- let cast = obj as HelperInstance;
- return typeof cast.compute === 'function' && typeof cast.destroy === 'function';
- }
- return false;
-}
-
const IS_CLASSIC_HELPER: unique symbol = Symbol('IS_CLASSIC_HELPER');
export interface SimpleHelper<T, P extends unknown[], N extends Dict<unknown>> {
@@ -182,7 +174,16 @@ class ClassicHelperManager implements HelperManager<ClassicHelperStateBucket> {
? definition.create()
: definition.create(this.ownerInjection);
- assert('expected HelperInstance', isHelperInstance(instance));
+ assert(
+ 'expected HelperInstance',
+ (function (instance: unknown): instance is HelperInstance {
+ if (instance !== null && typeof instance === 'object') {
+ let cast = instance as HelperInstance;
+ return typeof cast.compute === 'function' && typeof cast.destroy === 'function';
+ }
+ return false;
+ })(instance)
+ );
return {
instance, | true |
Other | emberjs | ember.js | 70058439456e66d659465b481c7d282084418940.json | Resolve some issues in TS conversion | packages/@ember/-internals/routing/lib/system/router.ts | @@ -302,6 +302,8 @@ class EmberRouter<R extends Route = Route> extends EmberObject.extend(Evented) i
return path.join('.');
}
+ // Note that owner is actually required in this scenario, but since it is strictly
+ // optional in other contexts trying to make it required here confuses TS.
constructor(owner?: Owner) {
super(owner);
| true |
Other | emberjs | ember.js | 70058439456e66d659465b481c7d282084418940.json | Resolve some issues in TS conversion | packages/@ember/-internals/runtime/lib/system/namespace.ts | @@ -34,19 +34,19 @@ import EmberObject from './object';
@extends EmberObject
@public
*/
-export default class Namespace extends EmberObject {
+class Namespace extends EmberObject {
static NAMESPACES = NAMESPACES;
static NAMESPACES_BY_ID = NAMESPACES_BY_ID;
static processAll = processAllNamespaces;
static byName = findNamespace;
+ declare isNamespace: true;
+
init(properties: object | undefined) {
super.init(properties);
addNamespace(this);
}
- readonly isNamespace = true;
-
toString(): string {
let existing_name = get(this, 'name') || get(this, 'modulePrefix');
if (existing_name) {
@@ -71,3 +71,8 @@ export default class Namespace extends EmberObject {
return super.destroy();
}
}
+
+// Declare on the prototype to have a single shared value.
+Namespace.prototype.isNamespace = true;
+
+export default Namespace; | true |
Other | emberjs | ember.js | 70058439456e66d659465b481c7d282084418940.json | Resolve some issues in TS conversion | packages/@ember/-internals/views/lib/views/core_view.ts | @@ -21,11 +21,7 @@ import states from './states';
*/
interface CoreView extends FrameworkObject, Evented, ActionHandler, View {}
-class CoreView extends FrameworkObject.extend(Evented, ActionHandler, {
- // Continue to declare `_states` here so that we have a single reference on the prototype
- // instead of one on each instance.
- _states: states,
-}) {
+class CoreView extends FrameworkObject.extend(Evented, ActionHandler) {
isView = true;
declare _states: typeof states;
@@ -100,4 +96,7 @@ class CoreView extends FrameworkObject.extend(Evented, ActionHandler, {
static isViewFactory = true;
}
+// Declare on the prototype to have a single shared value.
+CoreView.prototype._states = states;
+
export default CoreView; | true |
Other | emberjs | ember.js | 70058439456e66d659465b481c7d282084418940.json | Resolve some issues in TS conversion | packages/@ember/application/instance.ts | @@ -101,7 +101,7 @@ class ApplicationInstance extends EngineInstance {
return this;
}
- options = new CBootOptions(options);
+ options = new _BootOptions(options);
this.setupRegistry(options);
@@ -133,13 +133,13 @@ class ApplicationInstance extends EngineInstance {
_router?: Router;
get router() {
- if (this._router) {
- return this._router;
+ if (!this._router) {
+ let router = this.lookup('router:main');
+ assert('expected an instance of Router', router instanceof Router);
+ this._router = router;
}
- let router = this.lookup('router:main');
- assert('expected an instance of Router', router instanceof Router);
- return (this._router = router);
+ return this._router;
}
/**
@@ -299,8 +299,8 @@ class ApplicationInstance extends EngineInstance {
@param {Registry} registry
@param {BootOptions} options
*/
- static setupRegistry(registry: Registry, options: BootOptions | CBootOptions = {}) {
- let coptions = options instanceof CBootOptions ? options : new CBootOptions(options);
+ static setupRegistry(registry: Registry, options: BootOptions | _BootOptions = {}) {
+ let coptions = options instanceof _BootOptions ? options : new _BootOptions(options);
registry.register('-environment:main', coptions.toEnvironment(), {
instantiate: false,
@@ -335,7 +335,7 @@ class ApplicationInstance extends EngineInstance {
@namespace ApplicationInstance
@public
*/
-class CBootOptions {
+class _BootOptions {
/**
Interactive mode: whether we need to set up event delegation and invoke
lifecycle callbacks on Components. | true |
Other | emberjs | ember.js | 70058439456e66d659465b481c7d282084418940.json | Resolve some issues in TS conversion | packages/@ember/engine/index.ts | @@ -15,7 +15,7 @@ import { setupEngineRegistry } from '@ember/-internals/glimmer';
import RegistryProxyMixin from '@ember/-internals/runtime/lib/mixins/registry_proxy';
import { ResolverClass } from '@ember/-internals/container/lib/registry';
-function props(obj: any) {
+function props(obj: object) {
let properties = [];
for (let key in obj) { | true |
Other | emberjs | ember.js | 9adc2739b5accb9afeec9543dce2a66dd4974b2f.json | Upgrade eslint and prettier dependencies | package.json | @@ -94,8 +94,8 @@
"@simple-dom/document": "^1.4.0",
"@types/qunit": "^2.11.3",
"@types/rsvp": "^4.0.4",
- "@typescript-eslint/eslint-plugin": "^5.10.0",
- "@typescript-eslint/parser": "^5.13.0",
+ "@typescript-eslint/eslint-plugin": "^5.15.0",
+ "@typescript-eslint/parser": "^5.15.0",
"auto-dist-tag": "^2.1.1",
"aws-sdk": "^2.1083.0",
"babel-template": "^6.26.0",
@@ -117,8 +117,8 @@
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-yuidoc": "^0.9.1",
"ember-publisher": "0.0.7",
- "eslint": "^8.7.0",
- "eslint-config-prettier": "^8.3.0",
+ "eslint": "^8.11.0",
+ "eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-plugin-disable-features": "^0.1.3",
"eslint-plugin-ember-internal": "^2.0.0",
@@ -139,7 +139,7 @@
"mkdirp": "^1.0.4",
"mocha": "^9.2.0",
"npm-run-all": "^4.1.5",
- "prettier": "^2.1.2",
+ "prettier": "^2.6.0",
"puppeteer": "^13.4.1",
"qunit": "^2.14.0",
"rollup-plugin-commonjs": "^9.3.4", | true |
Other | emberjs | ember.js | 9adc2739b5accb9afeec9543dce2a66dd4974b2f.json | Upgrade eslint and prettier dependencies | yarn.lock | @@ -1269,16 +1269,16 @@
semver "^7.3.5"
typescript-memoize "^1.0.1"
-"@eslint/eslintrc@^1.0.5":
- version "1.0.5"
- resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.0.5.tgz#33f1b838dbf1f923bfa517e008362b78ddbbf318"
- integrity sha512-BLxsnmK3KyPunz5wmCCpqy0YelEoxxGmH73Is+Z74oOTMtExcjkr3dDR6quwrjh1YspA8DH9gnX1o069KiS9AQ==
+"@eslint/eslintrc@^1.2.1":
+ version "1.2.1"
+ resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.2.1.tgz#8b5e1c49f4077235516bc9ec7d41378c0f69b8c6"
+ integrity sha512-bxvbYnBPN1Gibwyp6NrpnFzA3YtRL3BBAyEAFVIpNTm2Rn4Vy87GA5M4aSn3InRrlsbX5N0GW7XIx+U4SAEKdQ==
dependencies:
ajv "^6.12.4"
debug "^4.3.2"
- espree "^9.2.0"
+ espree "^9.3.1"
globals "^13.9.0"
- ignore "^4.0.6"
+ ignore "^5.2.0"
import-fresh "^3.2.1"
js-yaml "^4.1.0"
minimatch "^3.0.4"
@@ -1800,118 +1800,84 @@
dependencies:
"@types/node" "*"
-"@typescript-eslint/eslint-plugin@^5.10.0":
- version "5.10.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.10.0.tgz#e90afea96dff8620892ad216b0e4ccdf8ee32d3a"
- integrity sha512-XXVKnMsq2fuu9K2KsIxPUGqb6xAImz8MEChClbXmE3VbveFtBUU5bzM6IPVWqzyADIgdkS2Ws/6Xo7W2TeZWjQ==
+"@typescript-eslint/eslint-plugin@^5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.15.0.tgz#c28ef7f2e688066db0b6a9d95fb74185c114fb9a"
+ integrity sha512-u6Db5JfF0Esn3tiAKELvoU5TpXVSkOpZ78cEGn/wXtT2RVqs2vkt4ge6N8cRCyw7YVKhmmLDbwI2pg92mlv7cA==
dependencies:
- "@typescript-eslint/scope-manager" "5.10.0"
- "@typescript-eslint/type-utils" "5.10.0"
- "@typescript-eslint/utils" "5.10.0"
+ "@typescript-eslint/scope-manager" "5.15.0"
+ "@typescript-eslint/type-utils" "5.15.0"
+ "@typescript-eslint/utils" "5.15.0"
debug "^4.3.2"
functional-red-black-tree "^1.0.1"
ignore "^5.1.8"
regexpp "^3.2.0"
semver "^7.3.5"
tsutils "^3.21.0"
-"@typescript-eslint/parser@^5.13.0":
- version "5.13.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.13.0.tgz#0394ed8f2f849273c0bf4b811994d177112ced5c"
- integrity sha512-GdrU4GvBE29tm2RqWOM0P5QfCtgCyN4hXICj/X9ibKED16136l9ZpoJvCL5pSKtmJzA+NRDzQ312wWMejCVVfg==
+"@typescript-eslint/parser@^5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.15.0.tgz#95f603f8fe6eca7952a99bfeef9b85992972e728"
+ integrity sha512-NGAYP/+RDM2sVfmKiKOCgJYPstAO40vPAgACoWPO/+yoYKSgAXIFaBKsV8P0Cc7fwKgvj27SjRNX4L7f4/jCKQ==
dependencies:
- "@typescript-eslint/scope-manager" "5.13.0"
- "@typescript-eslint/types" "5.13.0"
- "@typescript-eslint/typescript-estree" "5.13.0"
+ "@typescript-eslint/scope-manager" "5.15.0"
+ "@typescript-eslint/types" "5.15.0"
+ "@typescript-eslint/typescript-estree" "5.15.0"
debug "^4.3.2"
-"@typescript-eslint/scope-manager@5.10.0":
- version "5.10.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.10.0.tgz#bb5d872e8b9e36203908595507fbc4d3105329cb"
- integrity sha512-tgNgUgb4MhqK6DoKn3RBhyZ9aJga7EQrw+2/OiDk5hKf3pTVZWyqBi7ukP+Z0iEEDMF5FDa64LqODzlfE4O/Dg==
+"@typescript-eslint/scope-manager@5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.15.0.tgz#d97afab5e0abf4018d1289bd711be21676cdd0ee"
+ integrity sha512-EFiZcSKrHh4kWk0pZaa+YNJosvKE50EnmN4IfgjkA3bTHElPtYcd2U37QQkNTqwMCS7LXeDeZzEqnsOH8chjSg==
dependencies:
- "@typescript-eslint/types" "5.10.0"
- "@typescript-eslint/visitor-keys" "5.10.0"
+ "@typescript-eslint/types" "5.15.0"
+ "@typescript-eslint/visitor-keys" "5.15.0"
-"@typescript-eslint/scope-manager@5.13.0":
- version "5.13.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.13.0.tgz#cf6aff61ca497cb19f0397eea8444a58f46156b6"
- integrity sha512-T4N8UvKYDSfVYdmJq7g2IPJYCRzwtp74KyDZytkR4OL3NRupvswvmJQJ4CX5tDSurW2cvCc1Ia1qM7d0jpa7IA==
+"@typescript-eslint/type-utils@5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.15.0.tgz#d2c02eb2bdf54d0a645ba3a173ceda78346cf248"
+ integrity sha512-KGeDoEQ7gHieLydujGEFLyLofipe9PIzfvA/41urz4hv+xVxPEbmMQonKSynZ0Ks2xDhJQ4VYjB3DnRiywvKDA==
dependencies:
- "@typescript-eslint/types" "5.13.0"
- "@typescript-eslint/visitor-keys" "5.13.0"
-
-"@typescript-eslint/type-utils@5.10.0":
- version "5.10.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.10.0.tgz#8524b9479c19c478347a7df216827e749e4a51e5"
- integrity sha512-TzlyTmufJO5V886N+hTJBGIfnjQDQ32rJYxPaeiyWKdjsv2Ld5l8cbS7pxim4DeNs62fKzRSt8Q14Evs4JnZyQ==
- dependencies:
- "@typescript-eslint/utils" "5.10.0"
+ "@typescript-eslint/utils" "5.15.0"
debug "^4.3.2"
tsutils "^3.21.0"
-"@typescript-eslint/types@5.10.0":
- version "5.10.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.10.0.tgz#beb3cb345076f5b088afe996d57bcd1dfddaa75c"
- integrity sha512-wUljCgkqHsMZbw60IbOqT/puLfyqqD5PquGiBo1u1IS3PLxdi3RDGlyf032IJyh+eQoGhz9kzhtZa+VC4eWTlQ==
-
-"@typescript-eslint/types@5.13.0":
- version "5.13.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.13.0.tgz#da1de4ae905b1b9ff682cab0bed6b2e3be9c04e5"
- integrity sha512-LmE/KO6DUy0nFY/OoQU0XelnmDt+V8lPQhh8MOVa7Y5k2gGRd6U9Kp3wAjhB4OHg57tUO0nOnwYQhRRyEAyOyg==
-
-"@typescript-eslint/typescript-estree@5.10.0":
- version "5.10.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.10.0.tgz#4be24a3dea0f930bb1397c46187d0efdd955a224"
- integrity sha512-x+7e5IqfwLwsxTdliHRtlIYkgdtYXzE0CkFeV6ytAqq431ZyxCFzNMNR5sr3WOlIG/ihVZr9K/y71VHTF/DUQA==
- dependencies:
- "@typescript-eslint/types" "5.10.0"
- "@typescript-eslint/visitor-keys" "5.10.0"
- debug "^4.3.2"
- globby "^11.0.4"
- is-glob "^4.0.3"
- semver "^7.3.5"
- tsutils "^3.21.0"
+"@typescript-eslint/types@5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.15.0.tgz#c7bdd103843b1abae97b5518219d3e2a0d79a501"
+ integrity sha512-yEiTN4MDy23vvsIksrShjNwQl2vl6kJeG9YkVJXjXZnkJElzVK8nfPsWKYxcsGWG8GhurYXP4/KGj3aZAxbeOA==
-"@typescript-eslint/typescript-estree@5.13.0":
- version "5.13.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.13.0.tgz#b37c07b748ff030a3e93d87c842714e020b78141"
- integrity sha512-Q9cQow0DeLjnp5DuEDjLZ6JIkwGx3oYZe+BfcNuw/POhtpcxMTy18Icl6BJqTSd+3ftsrfuVb7mNHRZf7xiaNA==
+"@typescript-eslint/typescript-estree@5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.15.0.tgz#81513a742a9c657587ad1ddbca88e76c6efb0aac"
+ integrity sha512-Hb0e3dGc35b75xLzixM3cSbG1sSbrTBQDfIScqdyvrfJZVEi4XWAT+UL/HMxEdrJNB8Yk28SKxPLtAhfCbBInA==
dependencies:
- "@typescript-eslint/types" "5.13.0"
- "@typescript-eslint/visitor-keys" "5.13.0"
+ "@typescript-eslint/types" "5.15.0"
+ "@typescript-eslint/visitor-keys" "5.15.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"
-"@typescript-eslint/utils@5.10.0":
- version "5.10.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.10.0.tgz#c3d152a85da77c400e37281355561c72fb1b5a65"
- integrity sha512-IGYwlt1CVcFoE2ueW4/ioEwybR60RAdGeiJX/iDAw0t5w0wK3S7QncDwpmsM70nKgGTuVchEWB8lwZwHqPAWRg==
+"@typescript-eslint/utils@5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.15.0.tgz#468510a0974d3ced8342f37e6c662778c277f136"
+ integrity sha512-081rWu2IPKOgTOhHUk/QfxuFog8m4wxW43sXNOMSCdh578tGJ1PAaWPsj42LOa7pguh173tNlMigsbrHvh/mtA==
dependencies:
"@types/json-schema" "^7.0.9"
- "@typescript-eslint/scope-manager" "5.10.0"
- "@typescript-eslint/types" "5.10.0"
- "@typescript-eslint/typescript-estree" "5.10.0"
+ "@typescript-eslint/scope-manager" "5.15.0"
+ "@typescript-eslint/types" "5.15.0"
+ "@typescript-eslint/typescript-estree" "5.15.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
-"@typescript-eslint/visitor-keys@5.10.0":
- version "5.10.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.10.0.tgz#770215497ad67cd15a572b52089991d5dfe06281"
- integrity sha512-GMxj0K1uyrFLPKASLmZzCuSddmjZVbVj3Ouy5QVuIGKZopxvOr24JsS7gruz6C3GExE01mublZ3mIBOaon9zuQ==
+"@typescript-eslint/visitor-keys@5.15.0":
+ version "5.15.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.15.0.tgz#5669739fbf516df060f978be6a6dce75855a8027"
+ integrity sha512-+vX5FKtgvyHbmIJdxMJ2jKm9z2BIlXJiuewI8dsDYMp5LzPUcuTT78Ya5iwvQg3VqSVdmxyM8Anj1Jeq7733ZQ==
dependencies:
- "@typescript-eslint/types" "5.10.0"
- eslint-visitor-keys "^3.0.0"
-
-"@typescript-eslint/visitor-keys@5.13.0":
- version "5.13.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.13.0.tgz#f45ff55bcce16403b221ac9240fbeeae4764f0fd"
- integrity sha512-HLKEAS/qA1V7d9EzcpLFykTePmOQqOFim8oCvhY3pZgQ8Hi38hYpHd9e5GN6nQBFQNecNhws5wkS9Y5XIO0s/g==
- dependencies:
- "@typescript-eslint/types" "5.13.0"
+ "@typescript-eslint/types" "5.15.0"
eslint-visitor-keys "^3.0.0"
"@ungap/promise-all-settled@1.1.2":
@@ -4648,10 +4614,10 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
-eslint-config-prettier@^8.3.0:
- version "8.3.0"
- resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz#f7471b20b6fe8a9a9254cc684454202886a2dd7a"
- integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==
+eslint-config-prettier@^8.5.0:
+ version "8.5.0"
+ resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz#5a81680ec934beca02c7b1a61cf8ca34b66feab1"
+ integrity sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==
eslint-import-resolver-node@^0.3.6:
version "0.3.6"
@@ -4746,10 +4712,10 @@ eslint-scope@^5.1.1:
esrecurse "^4.3.0"
estraverse "^4.1.1"
-eslint-scope@^7.1.0:
- version "7.1.0"
- resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.1.0.tgz#c1f6ea30ac583031f203d65c73e723b01298f153"
- integrity sha512-aWwkhnS0qAXqNOgKOK0dJ2nvzEbhEvpy8OlJ9kZ0FeZnA6zpjv1/Vei+puGFFX7zkPCkHHXb7IDX3A+7yPrRWg==
+eslint-scope@^7.1.1:
+ version "7.1.1"
+ resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.1.1.tgz#fff34894c2f65e5226d3041ac480b4513a163642"
+ integrity sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==
dependencies:
esrecurse "^4.3.0"
estraverse "^5.2.0"
@@ -4778,28 +4744,33 @@ eslint-visitor-keys@^2.0.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8"
integrity "sha1-If3I+82ceVzAMh8FY3AglXUVEag= sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ=="
-eslint-visitor-keys@^3.0.0, eslint-visitor-keys@^3.1.0, eslint-visitor-keys@^3.2.0:
+eslint-visitor-keys@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.2.0.tgz#6fbb166a6798ee5991358bc2daa1ba76cc1254a1"
integrity sha512-IOzT0X126zn7ALX0dwFiUQEdsfzrm4+ISsQS8nukaJXwEyYKRSnEIIDULYg1mCtGp7UUXgfGl7BIolXREQK+XQ==
-eslint@^8.7.0:
- version "8.7.0"
- resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.7.0.tgz#22e036842ee5b7cf87b03fe237731675b4d3633c"
- integrity sha512-ifHYzkBGrzS2iDU7KjhCAVMGCvF6M3Xfs8X8b37cgrUlDt6bWRTpRh6T/gtSXv1HJ/BUGgmjvNvOEGu85Iif7w==
+eslint-visitor-keys@^3.3.0:
+ version "3.3.0"
+ resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
+ integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==
+
+eslint@^8.11.0:
+ version "8.11.0"
+ resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.11.0.tgz#88b91cfba1356fc10bb9eb592958457dfe09fb37"
+ integrity sha512-/KRpd9mIRg2raGxHRGwW9ZywYNAClZrHjdueHcrVDuO3a6bj83eoTirCCk0M0yPwOjWYKHwRVRid+xK4F/GHgA==
dependencies:
- "@eslint/eslintrc" "^1.0.5"
+ "@eslint/eslintrc" "^1.2.1"
"@humanwhocodes/config-array" "^0.9.2"
ajv "^6.10.0"
chalk "^4.0.0"
cross-spawn "^7.0.2"
debug "^4.3.2"
doctrine "^3.0.0"
escape-string-regexp "^4.0.0"
- eslint-scope "^7.1.0"
+ eslint-scope "^7.1.1"
eslint-utils "^3.0.0"
- eslint-visitor-keys "^3.2.0"
- espree "^9.3.0"
+ eslint-visitor-keys "^3.3.0"
+ espree "^9.3.1"
esquery "^1.4.0"
esutils "^2.0.2"
fast-deep-equal "^3.1.3"
@@ -4829,14 +4800,14 @@ esm@^3.2.4:
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.22.tgz#5062c2e22fee3ccfee4e8f20da768330da90d6e3"
integrity "sha1-UGLC4i/uPM/uTo8g2naDMNqQ1uM= sha512-z8YG7U44L82j1XrdEJcqZOLUnjxco8pO453gKOlaMD1/md1n/5QrscAmYG+oKUspsmDLuBFZrpbxI6aQ67yRxA=="
-espree@^9.2.0, espree@^9.3.0:
- version "9.3.0"
- resolved "https://registry.yarnpkg.com/espree/-/espree-9.3.0.tgz#c1240d79183b72aaee6ccfa5a90bc9111df085a8"
- integrity sha512-d/5nCsb0JcqsSEeQzFZ8DH1RmxPcglRWh24EFTlUEmCKoehXGdpsx0RkHDubqUI8LSAIKMQp4r9SzQ3n+sm4HQ==
+espree@^9.3.1:
+ version "9.3.1"
+ resolved "https://registry.yarnpkg.com/espree/-/espree-9.3.1.tgz#8793b4bc27ea4c778c19908e0719e7b8f4115bcd"
+ integrity sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==
dependencies:
acorn "^8.7.0"
acorn-jsx "^5.3.1"
- eslint-visitor-keys "^3.1.0"
+ eslint-visitor-keys "^3.3.0"
esprima@^4.0.0, esprima@~4.0.0:
version "4.0.1"
@@ -6161,11 +6132,6 @@ ieee754@1.1.13, ieee754@^1.1.4:
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84"
integrity "sha1-7BaFWOlaoYH9h9N/VcMrvLZwi4Q= sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
-ignore@^4.0.6:
- version "4.0.6"
- resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
- integrity "sha1-dQ49tYYgh7RzfrrIIH/9HvJ7Jfw= sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg=="
-
ignore@^5.1.1, ignore@^5.1.4, ignore@^5.1.8, ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
@@ -8471,16 +8437,16 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"
-prettier@^2.1.2:
- version "2.1.2"
- resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
- integrity "sha1-MFBwDa4uTItnxMP2Zs24r0BeHOU= sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg=="
-
prettier@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==
+prettier@^2.6.0:
+ version "2.6.0"
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.0.tgz#12f8f504c4d8ddb76475f441337542fa799207d4"
+ integrity sha512-m2FgJibYrBGGgQXNzfd0PuDGShJgRavjUoRCw1mZERIWVSXF0iLzLm+aOqTAbLnC3n6JzUhAA8uZnFVghHJ86A==
+
pretty-ms@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/pretty-ms/-/pretty-ms-3.1.0.tgz#e9cac9c76bf6ee52fe942dd9c6c4213153b12881" | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/glimmer/lib/component.ts | @@ -1,7 +1,6 @@
import { get, PROPERTY_DID_CHANGE } from '@ember/-internals/metal';
import { getOwner } from '@ember/-internals/owner';
import { TargetActionSupport } from '@ember/-internals/runtime';
-import { CoreObjectClass } from '@ember/-internals/runtime/lib/system/core_object';
import {
ActionSupport,
ChildViewsSupport,
@@ -649,415 +648,445 @@ let lazyEventsProcessed = new WeakMap<EventDispatcher, WeakSet<object>>();
@uses Ember.ViewStateSupport
@public
*/
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-interface ComponentClass extends CoreObjectClass<Component> {}
-interface Component
- extends CoreView,
- ChildViewsSupport,
- ViewStateSupport,
- ClassNamesSupport,
- TargetActionSupport,
- ActionSupport,
- ViewMixin {
- attributeBindings?: string[];
+interface ComponentMethods {
+ // Overrideable methods are defined here since you can't `declare` a method in a class
/**
- Layout can be used to wrap content in a component.
- @property layout
- @type Function
+ Called when the attributes passed into the component have been updated.
+ Called both during the initial render of a container and during a rerender.
+ Can be used in place of an observer; code placed here will be executed
+ every time any attribute updates.
+ @method didReceiveAttrs
@public
- */
- layout?: TemplateFactory | Template;
+ @since 1.13.0
+ */
+ didReceiveAttrs(): void;
/**
- The name of the layout to lookup if no layout is provided.
- By default `Component` will lookup a template with this name in
- `Ember.TEMPLATES` (a shared global object).
- @property layoutName
+ Called when the attributes passed into the component have been updated.
+ Called both during the initial render of a container and during a rerender.
+ Can be used in place of an observer; code placed here will be executed
+ every time any attribute updates.
+ @event didReceiveAttrs
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called after a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @method didRender
+ @public
+ @since 1.13.0
+ */
+ didRender(): void;
+
+ /**
+ Called after a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @event didRender
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called before a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @method willRender
+ @public
+ @since 1.13.0
+ */
+ willRender(): void;
+
+ /**
+ Called before a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @event willRender
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the attributes passed into the component have been changed.
+ Called only during a rerender, not during an initial render.
+ @method didUpdateAttrs
+ @public
+ @since 1.13.0
+ */
+ didUpdateAttrs(): void;
+
+ /**
+ Called when the attributes passed into the component have been changed.
+ Called only during a rerender, not during an initial render.
+ @event didUpdateAttrs
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the component is about to update and rerender itself.
+ Called only during a rerender, not during an initial render.
+ @method willUpdate
+ @public
+ @since 1.13.0
+ */
+ willUpdate(): void;
+
+ /**
+ Called when the component is about to update and rerender itself.
+ Called only during a rerender, not during an initial render.
+ @event willUpdate
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the component has updated and rerendered itself.
+ Called only during a rerender, not during an initial render.
+ @method didUpdate
+ @public
+ @since 1.13.0
+ */
+ didUpdate(): void;
+
+ /**
+ Called when the component has updated and rerendered itself.
+ Called only during a rerender, not during an initial render.
+ @event didUpdate
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ The HTML `id` of the component's element in the DOM. You can provide this
+ value yourself but it must be unique (just as in HTML):
+
+ ```handlebars
+ {{my-component elementId="a-really-cool-id"}}
+ ```
+
+ ```handlebars
+ <MyComponent @elementId="a-really-cool-id" />
+ ```
+ If not manually set a default value will be provided by the framework.
+ Once rendered an element's `elementId` is considered immutable and you
+ should never change it. If you need to compute a dynamic value for the
+ `elementId`, you should do this when the component or element is being
+ instantiated:
+
+ ```javascript
+ export default Component.extend({
+ init() {
+ this._super(...arguments);
+
+ var index = this.get('index');
+ this.set('elementId', `component-id${index}`);
+ }
+ });
+ ```
+
+ @property elementId
@type String
- @default undefined
- @private
+ @public
*/
- layoutName?: string;
}
+interface Component
+ extends CoreView,
+ ChildViewsSupport,
+ ViewStateSupport,
+ ClassNamesSupport,
+ TargetActionSupport,
+ ActionSupport,
+ ViewMixin,
+ ComponentMethods {}
-const Component = (CoreView.extend(
+class Component extends CoreView.extend(
ChildViewsSupport,
ViewStateSupport,
ClassNamesSupport,
TargetActionSupport,
ActionSupport,
ViewMixin,
{
- isComponent: true,
-
- init() {
- this._super(...arguments);
- this[IS_DISPATCHING_ATTRS] = false;
- this[DIRTY_TAG] = createTag();
- this[BOUNDS] = null;
-
- let eventDispatcher = this._dispatcher;
- if (eventDispatcher) {
- let lazyEventsProcessedForComponentClass = lazyEventsProcessed.get(eventDispatcher);
- if (!lazyEventsProcessedForComponentClass) {
- lazyEventsProcessedForComponentClass = new WeakSet<object>();
- lazyEventsProcessed.set(eventDispatcher, lazyEventsProcessedForComponentClass);
- }
+ // Make sure these are overrideable, but get a default
+ didReceiveAttrs() {},
+ didRender() {},
+ didUpdate() {},
+ didUpdateAttrs() {},
+ willRender() {},
+ willUpdate() {},
+ } as ComponentMethods
+) {
+ isComponent = true;
- let proto = Object.getPrototypeOf(this);
- if (!lazyEventsProcessedForComponentClass.has(proto)) {
- let lazyEvents = eventDispatcher.lazyEvents;
+ _superRerender?: ViewMixin['rerender'];
- lazyEvents.forEach((mappedEventName: string, event: string) => {
- if (mappedEventName !== null && typeof this[mappedEventName] === 'function') {
- eventDispatcher.setupHandlerForBrowserEvent(event);
- }
- });
+ init(properties: object | undefined) {
+ super.init(properties);
- lazyEventsProcessedForComponentClass.add(proto);
- }
- }
+ // Handle methods from ViewMixin
+ this._superRerender = this.rerender;
+ this.rerender = this._rerender;
+
+ this[IS_DISPATCHING_ATTRS] = false;
+ this[DIRTY_TAG] = createTag();
+ this[BOUNDS] = null;
- if (DEBUG && eventDispatcher && this.renderer._isInteractive && this.tagName === '') {
- let eventNames = [];
- let events = eventDispatcher.finalEventNameMapping;
+ const eventDispatcher = this._dispatcher;
+ if (eventDispatcher) {
+ let lazyEventsProcessedForComponentClass = lazyEventsProcessed.get(eventDispatcher);
+ if (!lazyEventsProcessedForComponentClass) {
+ lazyEventsProcessedForComponentClass = new WeakSet<object>();
+ lazyEventsProcessed.set(eventDispatcher, lazyEventsProcessedForComponentClass);
+ }
- for (let key in events) {
- let methodName = events[key];
+ let proto = Object.getPrototypeOf(this);
+ if (!lazyEventsProcessedForComponentClass.has(proto)) {
+ let lazyEvents = eventDispatcher.lazyEvents;
- if (typeof this[methodName] === 'function') {
- eventNames.push(methodName);
+ lazyEvents.forEach((mappedEventName: string, event: string) => {
+ if (mappedEventName !== null && typeof this[mappedEventName] === 'function') {
+ eventDispatcher.setupHandlerForBrowserEvent(event);
}
- }
- // If in a tagless component, assert that no event handlers are defined
- assert(
- `You can not define \`${eventNames}\` function(s) to handle DOM event in the \`${this}\` tagless component since it doesn't have any DOM element.`,
- !eventNames.length
- );
+ });
+
+ lazyEventsProcessedForComponentClass.add(proto);
}
- },
-
- get _dispatcher(): EventDispatcher | null {
- if (this.__dispatcher === undefined) {
- let owner = getOwner(this);
- assert('Component is unexpectedly missing an owner', owner);
-
- if ((owner.lookup('-environment:main') as Environment)!.isInteractive) {
- this.__dispatcher = owner.lookup('event_dispatcher:main');
- assert(
- 'Expected dispatcher to be an EventDispatcher',
- this.__dispatcher instanceof EventDispatcher
- );
- } else {
- // In FastBoot we have no EventDispatcher. Set to null to not try again to look it up.
- this.__dispatcher = null;
+ }
+
+ if (DEBUG && eventDispatcher && this.renderer._isInteractive && this.tagName === '') {
+ let eventNames = [];
+ let events = eventDispatcher.finalEventNameMapping;
+
+ for (let key in events) {
+ let methodName = events[key]!;
+
+ if (typeof this[methodName] === 'function') {
+ eventNames.push(methodName);
}
}
+ // If in a tagless component, assert that no event handlers are defined
+ assert(
+ `You can not define \`${eventNames}\` function(s) to handle DOM event in the \`${this}\` tagless component since it doesn't have any DOM element.`,
+ !eventNames.length
+ );
+ }
+ }
- return this.__dispatcher;
- },
-
- on(eventName: string) {
- this._dispatcher?.setupHandlerForEmberEvent(eventName);
- return this._super(...arguments);
- },
+ __dispatcher?: EventDispatcher | null;
- rerender() {
- dirtyTag(this[DIRTY_TAG]);
- this._super();
- },
+ get _dispatcher(): EventDispatcher | null {
+ if (this.__dispatcher === undefined) {
+ let owner = getOwner(this);
+ assert('Component is unexpectedly missing an owner', owner);
- [PROPERTY_DID_CHANGE](key: string, value?: unknown) {
- if (this[IS_DISPATCHING_ATTRS]) {
- return;
+ if ((owner.lookup('-environment:main') as Environment)!.isInteractive) {
+ let dispatcher = owner.lookup('event_dispatcher:main');
+ assert(
+ 'Expected dispatcher to be an EventDispatcher',
+ dispatcher instanceof EventDispatcher
+ );
+ this.__dispatcher = dispatcher;
+ } else {
+ // In FastBoot we have no EventDispatcher. Set to null to not try again to look it up.
+ this.__dispatcher = null;
}
+ }
- let args = this[ARGS];
- let reference = args !== undefined ? args[key] : undefined;
+ return this.__dispatcher;
+ }
- if (reference !== undefined && isUpdatableRef(reference)) {
- updateRef(reference, arguments.length === 2 ? value : get(this, key));
- }
- },
-
- getAttr(key: string) {
- // TODO Intimate API should be deprecated
- return this.get(key);
- },
-
- /**
- Normally, Ember's component model is "write-only". The component takes a
- bunch of attributes that it got passed in, and uses them to render its
- template.
-
- One nice thing about this model is that if you try to set a value to the
- same thing as last time, Ember (through HTMLBars) will avoid doing any
- work on the DOM.
-
- This is not just a performance optimization. If an attribute has not
- changed, it is important not to clobber the element's "hidden state".
- For example, if you set an input's `value` to the same value as before,
- it will clobber selection state and cursor position. In other words,
- setting an attribute is not **always** idempotent.
-
- This method provides a way to read an element's attribute and also
- update the last value Ember knows about at the same time. This makes
- setting an attribute idempotent.
-
- In particular, what this means is that if you get an `<input>` element's
- `value` attribute and then re-render the template with the same value,
- it will avoid clobbering the cursor and selection position.
- Since most attribute sets are idempotent in the browser, you typically
- can get away with reading attributes using jQuery, but the most reliable
- way to do so is through this method.
- @method readDOMAttr
-
- @param {String} name the name of the attribute
- @return String
- @public
- */
- readDOMAttr(name: string) {
- // TODO revisit this
- let _element = getViewElement(this);
+ on<Target>(
+ name: string,
+ target: Target,
+ method: string | ((this: Target, ...args: any[]) => void)
+ ): this;
+ on(name: string, method: ((...args: any[]) => void) | string): this;
+ on(name: string, target: any, method?: any) {
+ this._dispatcher?.setupHandlerForEmberEvent(name);
+ return super.on(name, target, method);
+ }
- assert(
- `Cannot call \`readDOMAttr\` on ${this} which does not have an element`,
- _element !== null
- );
+ // Changed to `rerender` on init
+ _rerender() {
+ dirtyTag(this[DIRTY_TAG]);
+ this._superRerender!();
+ }
+
+ [PROPERTY_DID_CHANGE](key: string, value?: unknown) {
+ if (this[IS_DISPATCHING_ATTRS]) {
+ return;
+ }
- let element = _element;
- let isSVG = element.namespaceURI === Namespace.SVG;
- let { type, normalized } = normalizeProperty(element, name);
+ let args = this[ARGS];
+ let reference = args !== undefined ? args[key] : undefined;
- if (isSVG || type === 'attr') {
- return element.getAttribute(normalized);
- }
+ if (reference !== undefined && isUpdatableRef(reference)) {
+ updateRef(reference, arguments.length === 2 ? value : get(this, key));
+ }
+ }
- return element[normalized];
- },
+ getAttr(key: string) {
+ // TODO Intimate API should be deprecated
+ return this.get(key);
+ }
- /**
- The WAI-ARIA role of the control represented by this view. For example, a
- button may have a role of type 'button', or a pane may have a role of
- type 'alertdialog'. This property is used by assistive software to help
- visually challenged users navigate rich web applications.
+ /**
+ Normally, Ember's component model is "write-only". The component takes a
+ bunch of attributes that it got passed in, and uses them to render its
+ template.
+
+ One nice thing about this model is that if you try to set a value to the
+ same thing as last time, Ember (through HTMLBars) will avoid doing any
+ work on the DOM.
+
+ This is not just a performance optimization. If an attribute has not
+ changed, it is important not to clobber the element's "hidden state".
+ For example, if you set an input's `value` to the same value as before,
+ it will clobber selection state and cursor position. In other words,
+ setting an attribute is not **always** idempotent.
+
+ This method provides a way to read an element's attribute and also
+ update the last value Ember knows about at the same time. This makes
+ setting an attribute idempotent.
+
+ In particular, what this means is that if you get an `<input>` element's
+ `value` attribute and then re-render the template with the same value,
+ it will avoid clobbering the cursor and selection position.
+ Since most attribute sets are idempotent in the browser, you typically
+ can get away with reading attributes using jQuery, but the most reliable
+ way to do so is through this method.
+ @method readDOMAttr
+
+ @param {String} name the name of the attribute
+ @return String
+ @public
+ */
+ readDOMAttr(name: string) {
+ // TODO revisit this
+ let _element = getViewElement(this);
- The full list of valid WAI-ARIA roles is available at:
- [https://www.w3.org/TR/wai-aria/#roles_categorization](https://www.w3.org/TR/wai-aria/#roles_categorization)
+ assert(
+ `Cannot call \`readDOMAttr\` on ${this} which does not have an element`,
+ _element !== null
+ );
- @property ariaRole
- @type String
- @default null
- @public
- */
+ let element = _element;
+ let isSVG = element.namespaceURI === Namespace.SVG;
+ let { type, normalized } = normalizeProperty(element, name);
- /**
- Enables components to take a list of parameters as arguments.
- For example, a component that takes two parameters with the names
- `name` and `age`:
+ if (isSVG || type === 'attr') {
+ return element.getAttribute(normalized);
+ }
- ```app/components/my-component.js
- import Component from '@ember/component';
+ return element[normalized];
+ }
- let MyComponent = Component.extend();
+ declare attributeBindings?: string[];
- MyComponent.reopenClass({
- positionalParams: ['name', 'age']
- });
+ /**
+ Layout can be used to wrap content in a component.
+ @property layout
+ @type Function
+ @public
+ */
+ declare layout?: TemplateFactory | Template;
- export default MyComponent;
- ```
+ /**
+ The name of the layout to lookup if no layout is provided.
+ By default `Component` will lookup a template with this name in
+ `Ember.TEMPLATES` (a shared global object).
+ @property layoutName
+ @type String
+ @default undefined
+ @private
+ */
+ declare layoutName?: string;
- It can then be invoked like this:
+ /**
+ The WAI-ARIA role of the control represented by this view. For example, a
+ button may have a role of type 'button', or a pane may have a role of
+ type 'alertdialog'. This property is used by assistive software to help
+ visually challenged users navigate rich web applications.
- ```hbs
- {{my-component "John" 38}}
- ```
+ The full list of valid WAI-ARIA roles is available at:
+ [https://www.w3.org/TR/wai-aria/#roles_categorization](https://www.w3.org/TR/wai-aria/#roles_categorization)
- The parameters can be referred to just like named parameters:
+ @property ariaRole
+ @type String
+ @default undefined
+ @public
+ */
+ declare ariaRole?: string;
- ```hbs
- Name: {{name}}, Age: {{age}}.
- ```
+ static isComponentFactory = true;
- Using a string instead of an array allows for an arbitrary number of
- parameters:
+ static toString() {
+ return '@ember/component';
+ }
+}
- ```app/components/my-component.js
- import Component from '@ember/component';
+Component.reopenClass({
+ /**
+ Enables components to take a list of parameters as arguments.
+ For example, a component that takes two parameters with the names
+ `name` and `age`:
- let MyComponent = Component.extend();
+ ```app/components/my-component.js
+ import Component from '@ember/component';
- MyComponent.reopenClass({
- positionalParams: 'names'
- });
+ let MyComponent = Component.extend();
- export default MyComponent;
- ```
+ MyComponent.reopenClass({
+ positionalParams: ['name', 'age']
+ });
- It can then be invoked like this:
+ export default MyComponent;
+ ```
- ```hbs
- {{my-component "John" "Michael" "Scott"}}
- ```
- The parameters can then be referred to by enumerating over the list:
+ It can then be invoked like this:
- ```hbs
- {{#each names as |name|}}{{name}}{{/each}}
- ```
+ ```hbs
+ {{my-component "John" 38}}
+ ```
- @static
- @public
- @property positionalParams
- @since 1.13.0
- */
+ The parameters can be referred to just like named parameters:
- /**
- Called when the attributes passed into the component have been updated.
- Called both during the initial render of a container and during a rerender.
- Can be used in place of an observer; code placed here will be executed
- every time any attribute updates.
- @method didReceiveAttrs
- @public
- @since 1.13.0
- */
- didReceiveAttrs() {},
+ ```hbs
+ Name: {{name}}, Age: {{age}}.
+ ```
- /**
- Called when the attributes passed into the component have been updated.
- Called both during the initial render of a container and during a rerender.
- Can be used in place of an observer; code placed here will be executed
- every time any attribute updates.
- @event didReceiveAttrs
- @public
- @since 1.13.0
- */
-
- /**
- Called after a component has been rendered, both on initial render and
- in subsequent rerenders.
- @method didRender
- @public
- @since 1.13.0
- */
- didRender() {},
+ Using a string instead of an array allows for an arbitrary number of
+ parameters:
- /**
- Called after a component has been rendered, both on initial render and
- in subsequent rerenders.
- @event didRender
- @public
- @since 1.13.0
- */
-
- /**
- Called before a component has been rendered, both on initial render and
- in subsequent rerenders.
- @method willRender
- @public
- @since 1.13.0
- */
- willRender() {},
+ ```app/components/my-component.js
+ import Component from '@ember/component';
- /**
- Called before a component has been rendered, both on initial render and
- in subsequent rerenders.
- @event willRender
- @public
- @since 1.13.0
- */
-
- /**
- Called when the attributes passed into the component have been changed.
- Called only during a rerender, not during an initial render.
- @method didUpdateAttrs
- @public
- @since 1.13.0
- */
- didUpdateAttrs() {},
+ let MyComponent = Component.extend();
- /**
- Called when the attributes passed into the component have been changed.
- Called only during a rerender, not during an initial render.
- @event didUpdateAttrs
- @public
- @since 1.13.0
- */
-
- /**
- Called when the component is about to update and rerender itself.
- Called only during a rerender, not during an initial render.
- @method willUpdate
- @public
- @since 1.13.0
- */
- willUpdate() {},
+ MyComponent.reopenClass({
+ positionalParams: 'names'
+ });
- /**
- Called when the component is about to update and rerender itself.
- Called only during a rerender, not during an initial render.
- @event willUpdate
- @public
- @since 1.13.0
- */
-
- /**
- Called when the component has updated and rerendered itself.
- Called only during a rerender, not during an initial render.
- @method didUpdate
- @public
- @since 1.13.0
- */
- didUpdate() {},
+ export default MyComponent;
+ ```
- /**
- Called when the component has updated and rerendered itself.
- Called only during a rerender, not during an initial render.
- @event didUpdate
- @public
- @since 1.13.0
- */
-
- /**
- The HTML `id` of the component's element in the DOM. You can provide this
- value yourself but it must be unique (just as in HTML):
-
- ```handlebars
- {{my-component elementId="a-really-cool-id"}}
- ```
-
- ```handlebars
- <MyComponent @elementId="a-really-cool-id" />
- ```
- If not manually set a default value will be provided by the framework.
- Once rendered an element's `elementId` is considered immutable and you
- should never change it. If you need to compute a dynamic value for the
- `elementId`, you should do this when the component or element is being
- instantiated:
-
- ```javascript
- export default Component.extend({
- init() {
- this._super(...arguments);
-
- var index = this.get('index');
- this.set('elementId', `component-id${index}`);
- }
- });
- ```
+ It can then be invoked like this:
- @property elementId
- @type String
- @public
- */
- }
-) as unknown) as ComponentClass;
+ ```hbs
+ {{my-component "John" "Michael" "Scott"}}
+ ```
+ The parameters can then be referred to by enumerating over the list:
-Component.toString = () => '@ember/component';
+ ```hbs
+ {{#each names as |name|}}{{name}}{{/each}}
+ ```
-Component.reopenClass({
- isComponentFactory: true,
+ @static
+ @public
+ @property positionalParams
+ @since 1.13.0
+ */
positionalParams: [],
});
| true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/glimmer/lib/renderer.ts | @@ -293,7 +293,9 @@ export class Renderer {
private _lastRevision = -1;
private _destroyed = false;
- private _isInteractive: boolean;
+
+ /** @private */
+ _isInteractive: boolean;
readonly _runtimeResolver: ResolverImpl;
| true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/meta/lib/meta.ts | @@ -1,3 +1,4 @@
+import { ComputedProperty } from '@ember/-internals/metal';
import { symbol, toString } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { isDestroyed } from '@glimmer/destroyable';
@@ -330,7 +331,7 @@ export class Meta {
}
/** @internal */
- forEachDescriptors(fn: Function) {
+ forEachDescriptors(fn: (key: string, value: ComputedProperty) => void) {
let pointer: Meta | null = this;
let seen: Set<any> | undefined;
while (pointer !== null) { | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/metal/index.ts | @@ -2,7 +2,14 @@ export { default as computed, autoComputed, isComputed, ComputedProperty } from
export { getCachedValueFor } from './lib/computed_cache';
export { default as alias } from './lib/alias';
export { deprecateProperty } from './lib/deprecate_property';
-export { PROXY_CONTENT, _getPath, get, _getProp } from './lib/property_get';
+export {
+ PROXY_CONTENT,
+ _getPath,
+ get,
+ _getProp,
+ HasUnknownProperty,
+ hasUnknownProperty,
+} from './lib/property_get';
export { set, _setProp, trySet } from './lib/property_set';
export {
objectAt, | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/metal/lib/is_empty.ts | @@ -1,4 +1,4 @@
-import { get, MaybeHasUnknownProperty } from './property_get';
+import { get, hasUnknownProperty } from './property_get';
/**
@module @ember/utils
*/
@@ -39,10 +39,7 @@ export default function isEmpty(obj: unknown): boolean {
return true;
}
- if (
- typeof (obj as MaybeHasUnknownProperty).unknownProperty !== 'function' &&
- typeof (obj as HasSize).size === 'number'
- ) {
+ if (!hasUnknownProperty(obj) && typeof (obj as HasSize).size === 'number') {
return !(obj as HasSize).size;
}
| true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/metal/lib/mixin.ts | @@ -383,7 +383,11 @@ function updateObserversAndListeners(obj: object, key: string, fn: Function, add
}
}
-export function applyMixin(obj: { [key: string]: any }, mixins: Mixin[], _hideKeys = false) {
+export function applyMixin(
+ obj: { [key: string]: any },
+ mixins: Array<Mixin | Record<string, unknown>>,
+ _hideKeys = false
+) {
let descs = Object.create(null);
let values = Object.create(null);
let meta = metaFor(obj);
@@ -600,7 +604,9 @@ export default class Mixin {
@private
@internal
*/
- reopen(...args: any[]) {
+ // Args should be `Array<Mixin | Record<string, unknown>>` but this causes
+ // types to be overly strict.
+ reopen(...args: any[]): this | undefined {
if (args.length === 0) {
return;
} | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/metal/lib/property_get.ts | @@ -24,8 +24,16 @@ if (DEBUG) {
};
}
-export interface MaybeHasUnknownProperty {
- unknownProperty?: (keyName: string) => any;
+export interface HasUnknownProperty {
+ unknownProperty: (keyName: string) => any;
+}
+
+export function hasUnknownProperty(val: unknown): val is HasUnknownProperty {
+ return (
+ typeof val === 'object' &&
+ val !== null &&
+ typeof (val as HasUnknownProperty).unknownProperty === 'function'
+ );
}
interface MaybeHasIsDestroyed {
@@ -111,9 +119,9 @@ export function _getProp(obj: unknown, keyName: string) {
value === undefined &&
typeof obj === 'object' &&
!(keyName in obj) &&
- typeof (obj as MaybeHasUnknownProperty).unknownProperty === 'function'
+ hasUnknownProperty(obj)
) {
- value = (obj as MaybeHasUnknownProperty).unknownProperty!(keyName);
+ value = obj.unknownProperty(keyName);
}
if (isTracking()) { | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/runtime/lib/mixins/evented.d.ts | @@ -13,13 +13,6 @@ interface Evented {
method: string | ((this: Target, ...args: any[]) => void)
): this;
on(name: string, method: ((...args: any[]) => void) | string): this;
- // Allow for easier super calls
- on<Target>(
- name: string,
- ...args:
- | [Target, string | ((this: Target, ...args: any[]) => void)]
- | [((...args: any[]) => void) | string]
- ): this;
/**
* Subscribes a function to a named event and then cancels the subscription
* after the first time the event is triggered. It is good to use ``one`` when | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/runtime/lib/system/core_object.d.ts | @@ -1,148 +0,0 @@
-import { Owner } from '@ember/-internals/owner';
-
-/**
- * Used to infer the type of ember classes of type `T`.
- *
- * Generally you would use `EmberClass.create()` instead of `new EmberClass()`.
- *
- * The single-arg constructor is required by the typescript compiler.
- * The multi-arg constructor is included for better ergonomics.
- *
- * Implementation is carefully chosen for the reasons described in
- * https://github.com/typed-ember/ember-typings/pull/29
- */
-/** @internal */
-export type EmberClassConstructor<T> = new (owner: Owner) => T;
-
-/** @internal */
-export type MergeArray<Arr extends any[]> = Arr extends [infer T, ...infer Rest]
- ? T & MergeArray<Rest>
- : unknown; // TODO: Is this correct?
-
-/** @internal */
-export interface CoreObjectClass<Instance> extends EmberClassConstructor<Instance> {
- /** @internal */
- extend<Statics>(
- this: EmberClassConstructor<Instance>,
- ...args: any[]
- ): CoreObjectClass<Statics & Instance>;
-
- /** @internal */
- reopen(...args: any[]): any;
-
- /** @internal */
- reopenClass(...args: any[]): any;
-
- /** @internal */
- create<Class extends EmberClassConstructor<Instance>, Args extends Array<Record<string, any>>>(
- this: Class,
- ...args: Args
- ): InstanceType<Class> & MergeArray<Args>;
-}
-
-export default class CoreObject {
- /** @internal */
- static extend<Statics, Instance>(
- this: Statics & EmberClassConstructor<Instance>,
- ...args: any[]
- ): Readonly<Statics> & CoreObjectClass<Instance>;
-
- /** @internal */
- static reopen(...args: any[]): any;
-
- /** @internal */
- static reopenClass(...args: any[]): any;
-
- /**
- * CoreObject constructor takes owner.
- */
- constructor(owner: Owner);
-
- /** @internal */
- _super(...args: any[]): any;
-
- /**
- * An overridable method called when objects are instantiated. By default,
- * does nothing unless it is overridden during class definition.
- */
- init(props: object | undefined): void;
-
- /**
- * Defines the properties that will be concatenated from the superclass (instead of overridden).
- * @default null
- */
- concatenatedProperties: string[];
-
- /**
- * Destroyed object property flag. If this property is true the observers and bindings were
- * already removed by the effect of calling the destroy() method.
- * @default false
- */
- isDestroyed: boolean;
- /**
- * Destruction scheduled flag. The destroy() method has been called. The object stays intact
- * until the end of the run loop at which point the isDestroyed flag is set.
- * @default false
- */
- isDestroying: boolean;
-
- // NOTE That the actual CoreObject#destroy returns `this`;
- /**
- * Destroys an object by setting the `isDestroyed` flag and removing its
- * metadata, which effectively destroys observers and bindings.
- * If you try to set a property on a destroyed object, an exception will be
- * raised.
- * Note that destruction is scheduled for the end of the run loop and does not
- * happen immediately. It will set an isDestroying flag immediately.
- * @return receiver
- */
- destroy(): void;
-
- /**
- * Override to implement teardown.
- */
- willDestroy(): void;
-
- /**
- * Returns a string representation which attempts to provide more information than Javascript's toString
- * typically does, in a generic way for all Ember objects (e.g., "<App.Person:ember1024>").
- * @return string representation
- */
- toString(): string;
-
- static create<Class extends typeof CoreObject, Args extends Array<Record<string, any>>>(
- this: Class,
- ...args: Args
- ): InstanceType<Class> & MergeArray<Args>;
-
- /** @internal */
- static detect<Statics, Instance>(
- this: Statics & EmberClassConstructor<Instance>,
- obj: any
- ): obj is Readonly<Statics> & EmberClassConstructor<Instance>;
-
- /** @internal */
- static detectInstance<Instance>(this: EmberClassConstructor<Instance>, obj: any): obj is Instance;
-
- /**
- * Iterate over each computed property for the class, passing its name and any
- * associated metadata (see metaForProperty) to the callback.
- * @internal
- */
- static eachComputedProperty(callback: (...args: any[]) => any, binding: {}): void;
- /**
- * Returns the original hash that was passed to meta().
- * @param key property name
- * @internal
- */
- static metaForProperty(key: string): {};
-
- /** @internal */
- static isClass: boolean;
-
- /** @internal */
- static isMethod: boolean;
-
- /** @internal */
- static superclass: unknown;
-} | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/runtime/lib/system/core_object.ts | @@ -3,7 +3,7 @@
*/
import { getFactoryFor, setFactoryFor } from '@ember/-internals/container';
-import { getOwner } from '@ember/-internals/owner';
+import { getOwner, Owner } from '@ember/-internals/owner';
import { guidFor, makeArray, isInternalSymbol } from '@ember/-internals/utils';
import { meta } from '@ember/-internals/meta';
import {
@@ -16,6 +16,9 @@ import {
descriptorForProperty,
isClassicDecorator,
DEBUG_INJECTION_FUNCTIONS,
+ ComputedProperty,
+ HasUnknownProperty,
+ hasUnknownProperty,
} from '@ember/-internals/metal';
import ActionHandler from '../mixins/action_handler';
import { assert } from '@ember/debug';
@@ -24,6 +27,35 @@ import { _WeakSet as WeakSet } from '@glimmer/util';
import { destroy, isDestroying, isDestroyed, registerDestructor } from '@glimmer/destroyable';
import { OWNER } from '@glimmer/owner';
+type EmberClassConstructor<T> = new (owner: Owner) => T;
+
+type MergeArray<Arr extends any[]> = Arr extends [infer T, ...infer Rest]
+ ? T & MergeArray<Rest>
+ : unknown; // TODO: Is this correct?
+
+interface HasSetUnknownProperty {
+ setUnknownProperty: (keyName: string, value: any) => any;
+}
+
+function hasSetUnknownProperty(val: unknown): val is HasSetUnknownProperty {
+ return (
+ typeof val === 'object' &&
+ val !== null &&
+ typeof (val as HasSetUnknownProperty).setUnknownProperty === 'function'
+ );
+}
+
+interface HasToStringExtension {
+ toStringExtension: () => void;
+}
+
+function hasToStringExtension(val: unknown): val is HasToStringExtension {
+ return (
+ typeof val === 'object' &&
+ val !== null &&
+ typeof (val as HasToStringExtension).toStringExtension === 'function'
+ );
+}
const reopen = Mixin.prototype.reopen;
const wasApplied = new WeakSet();
@@ -33,13 +65,13 @@ const initCalled = DEBUG ? new WeakSet() : undefined; // only used in debug buil
const destroyCalled = new Set();
-function ensureDestroyCalled(instance) {
+function ensureDestroyCalled(instance: CoreObject) {
if (!destroyCalled.has(instance)) {
instance.destroy();
}
}
-function initialize(obj, properties) {
+function initialize(obj: CoreObject, properties?: unknown) {
let m = meta(obj);
if (properties !== undefined) {
@@ -56,14 +88,10 @@ function initialize(obj, properties) {
let concatenatedProperties = obj.concatenatedProperties;
let mergedProperties = obj.mergedProperties;
- let hasConcatenatedProps =
- concatenatedProperties !== undefined && concatenatedProperties.length > 0;
- let hasMergedProps = mergedProperties !== undefined && mergedProperties.length > 0;
let keyNames = Object.keys(properties);
- for (let i = 0; i < keyNames.length; i++) {
- let keyName = keyNames[i];
+ for (let keyName of keyNames) {
let value = properties[keyName];
assert(
@@ -86,7 +114,11 @@ function initialize(obj, properties) {
let isDescriptor = possibleDesc !== undefined;
if (!isDescriptor) {
- if (hasConcatenatedProps && concatenatedProperties.indexOf(keyName) > -1) {
+ if (
+ concatenatedProperties !== undefined &&
+ concatenatedProperties.length > 0 &&
+ concatenatedProperties.indexOf(keyName) > -1
+ ) {
let baseValue = obj[keyName];
if (baseValue) {
value = makeArray(baseValue).concat(value);
@@ -95,15 +127,19 @@ function initialize(obj, properties) {
}
}
- if (hasMergedProps && mergedProperties.indexOf(keyName) > -1) {
+ if (
+ mergedProperties !== undefined &&
+ mergedProperties.length > 0 &&
+ mergedProperties.indexOf(keyName) > -1
+ ) {
let baseValue = obj[keyName];
value = Object.assign({}, baseValue, value);
}
}
if (isDescriptor) {
possibleDesc.set(obj, keyName, value);
- } else if (typeof obj.setUnknownProperty === 'function' && !(keyName in obj)) {
+ } else if (hasSetUnknownProperty(obj) && !(keyName in obj)) {
obj.setUnknownProperty(keyName, value);
} else {
if (DEBUG) {
@@ -117,7 +153,7 @@ function initialize(obj, properties) {
// using DEBUG here to avoid the extraneous variable when not needed
if (DEBUG) {
- initCalled.add(obj);
+ initCalled!.add(obj);
}
obj.init(properties);
@@ -131,7 +167,7 @@ function initialize(obj, properties) {
}
}
- sendEvent(obj, 'init', undefined, undefined, undefined, m);
+ sendEvent(obj, 'init', undefined, undefined, m);
}
/**
@@ -195,17 +231,20 @@ function initialize(obj, properties) {
@class CoreObject
@public
*/
+interface CoreObject {
+ /** @internal */
+ _super(...args: any[]): any;
+}
class CoreObject {
- constructor(owner) {
+ constructor(owner?: Owner) {
this[OWNER] = owner;
// prepare prototype...
- this.constructor.proto();
+ (this.constructor as typeof CoreObject).proto();
- let self = this;
-
- if (DEBUG && typeof self.unknownProperty === 'function') {
- let messageFor = (obj, property) => {
+ let self;
+ if (DEBUG && hasUnknownProperty(this)) {
+ let messageFor = (obj: unknown, property: unknown) => {
return (
`You attempted to access the \`${String(property)}\` property (of ${obj}).\n` +
`Since Ember 3.1, this is usually fine as you no longer need to use \`.get()\`\n` +
@@ -221,12 +260,12 @@ class CoreObject {
/* globals Proxy Reflect */
self = new Proxy(this, {
- get(target, property, receiver) {
+ get(target: CoreObject & HasUnknownProperty, property, receiver) {
if (property === PROXY_CONTENT) {
return target;
} else if (
// init called will be set on the proxy, not the target, so get with the receiver
- !initCalled.has(receiver) ||
+ !initCalled!.has(receiver) ||
typeof property === 'symbol' ||
isInternalSymbol(property) ||
property === 'toJSON' ||
@@ -251,10 +290,13 @@ class CoreObject {
}
},
});
+ } else {
+ self = this;
}
+ const destroyable = self;
registerDestructor(self, ensureDestroyCalled, true);
- registerDestructor(self, () => self.willDestroy());
+ registerDestructor(self, () => destroyable.willDestroy());
// disable chains
let m = meta(self);
@@ -267,7 +309,7 @@ class CoreObject {
}
}
- reopen(...args) {
+ reopen(...args: Array<Mixin | Record<string, unknown>>) {
applyMixin(this, args);
return this;
}
@@ -304,7 +346,7 @@ class CoreObject {
@method init
@public
*/
- init() {}
+ init(_properties: object | undefined) {}
/**
Defines the properties that will be concatenated from the superclass
@@ -469,7 +511,7 @@ class CoreObject {
return isDestroyed(this);
}
- set isDestroyed(value) {
+ set isDestroyed(_value) {
assert(`You cannot set \`${this}.isDestroyed\` directly, please use \`.destroy()\`.`, false);
}
@@ -487,7 +529,7 @@ class CoreObject {
return isDestroying(this);
}
- set isDestroying(value) {
+ set isDestroying(_value) {
assert(`You cannot set \`${this}.isDestroying\` directly, please use \`.destroy()\`.`, false);
}
@@ -566,8 +608,7 @@ class CoreObject {
@public
*/
toString() {
- let hasToStringExtension = typeof this.toStringExtension === 'function';
- let extension = hasToStringExtension ? `:${this.toStringExtension()}` : '';
+ let extension = hasToStringExtension(this) ? `:${this.toStringExtension()}` : '';
return `<${getFactoryFor(this) || '(unknown)'}:${guidFor(this)}${extension}>`;
}
@@ -666,9 +707,15 @@ class CoreObject {
@param {Object} [arguments]* Object containing values to use within the new class
@public
*/
- static extend() {
+ // Args should be `Array<Mixin | Record<string, unknown>>` but this causes
+ // types to be overly strict.
+ static extend<Statics, Instance>(
+ this: Statics & EmberClassConstructor<Instance>,
+ ...mixins: any[]
+ ): Readonly<Statics> & EmberClassConstructor<Instance>;
+ static extend(...mixins: any[]) {
let Class = class extends this {};
- reopen.apply(Class.PrototypeMixin, arguments);
+ reopen.apply(Class.PrototypeMixin, mixins);
return Class;
}
@@ -713,7 +760,12 @@ class CoreObject {
@param [arguments]*
@public
*/
- static create(props, extra) {
+ static create<Class extends typeof CoreObject, Args extends Array<Record<string, any>>>(
+ this: Class,
+ ...args: Args
+ ): InstanceType<Class> & MergeArray<Args>;
+ static create(...args: Record<string, unknown>[]) {
+ let props = args[0];
let instance;
if (props !== undefined) {
@@ -723,10 +775,10 @@ class CoreObject {
instance = new this();
}
- if (extra === undefined) {
+ if (args.length <= 1) {
initialize(instance, props);
} else {
- initialize(instance, flattenProps.apply(this, arguments));
+ initialize(instance, flattenProps.apply(this, args));
}
return instance;
@@ -766,9 +818,11 @@ class CoreObject {
@static
@public
*/
- static reopen() {
+ // Args should be `Array<Mixin | Record<string, unknown>>` but this causes
+ // types to be overly strict.
+ static reopen(...args: any[]) {
this.willReopen();
- reopen.apply(this.PrototypeMixin, arguments);
+ reopen.apply(this.PrototypeMixin, args);
return this;
}
@@ -847,25 +901,25 @@ class CoreObject {
@static
@public
*/
- static reopenClass() {
- applyMixin(this, arguments);
+ static reopenClass(...mixins: Array<Mixin | Record<string, unknown>>) {
+ applyMixin(this, mixins);
return this;
}
- static detect(obj) {
+ static detect(obj: unknown) {
if ('function' !== typeof obj) {
return false;
}
while (obj) {
if (obj === this) {
return true;
}
- obj = obj.superclass;
+ obj = (obj as typeof CoreObject).superclass;
}
return false;
}
- static detectInstance(obj) {
+ static detectInstance(obj: unknown) {
return obj instanceof this;
}
@@ -900,7 +954,7 @@ class CoreObject {
@param key {String} property name
@private
*/
- static metaForProperty(key) {
+ static metaForProperty(key: string) {
let proto = this.proto(); // ensure prototype is initialized
let possibleDesc = descriptorForProperty(proto, key);
@@ -922,11 +976,11 @@ class CoreObject {
@param {Object} binding
@private
*/
- static eachComputedProperty(callback, binding = this) {
+ static eachComputedProperty(callback: (name: string, meta: unknown) => void, binding = this) {
this.proto(); // ensure prototype is initialized
let empty = {};
- meta(this.prototype).forEachDescriptors((name, descriptor) => {
+ meta(this.prototype).forEachDescriptors((name: string, descriptor: ComputedProperty) => {
if (descriptor.enumerable) {
let meta = descriptor._meta || empty;
callback.call(binding, name, meta);
@@ -970,22 +1024,21 @@ class CoreObject {
static toString() {
return `<${getFactoryFor(this) || '(unknown)'}:constructor>`;
}
-}
-CoreObject.isClass = true;
-CoreObject.isMethod = false;
+ static isClass = true;
+ static isMethod = false;
-function flattenProps(...props) {
- let { concatenatedProperties, mergedProperties } = this;
- let hasConcatenatedProps =
- concatenatedProperties !== undefined && concatenatedProperties.length > 0;
- let hasMergedProps = mergedProperties !== undefined && mergedProperties.length > 0;
+ static _onLookup?: (debugContainerKey: string) => void;
+ static _lazyInjections?: () => void;
- let initProperties = {};
+ declare concatenatedProperties?: string[] | string;
+ declare mergedProperties?: unknown[];
+}
- for (let i = 0; i < props.length; i++) {
- let properties = props[i];
+function flattenProps(this: typeof CoreObject, ...props: Array<Record<string, unknown>>) {
+ let initProperties = {};
+ for (let properties of props) {
assert(
'EmberObject.create no longer supports mixing in other ' +
'definitions, use .extend & .create separately instead.',
@@ -995,25 +1048,8 @@ function flattenProps(...props) {
let keyNames = Object.keys(properties);
for (let j = 0, k = keyNames.length; j < k; j++) {
- let keyName = keyNames[j];
+ let keyName = keyNames[j]!;
let value = properties[keyName];
-
- if (hasConcatenatedProps && concatenatedProperties.indexOf(keyName) > -1) {
- let baseValue = initProperties[keyName];
-
- if (baseValue) {
- value = makeArray(baseValue).concat(value);
- } else {
- value = makeArray(value);
- }
- }
-
- if (hasMergedProps && mergedProperties.indexOf(keyName) > -1) {
- let baseValue = initProperties[keyName];
-
- value = Object.assign({}, baseValue, value);
- }
-
initProperties[keyName] = value;
}
}
@@ -1028,7 +1064,7 @@ if (DEBUG) {
@private
@method _onLookup
*/
- CoreObject._onLookup = function injectedPropertyAssertion(debugContainerKey) {
+ CoreObject._onLookup = function injectedPropertyAssertion(debugContainerKey: string) {
let [type] = debugContainerKey.split(':');
let proto = this.proto();
| true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/views/lib/mixins/class_names_support.d.ts | @@ -1,7 +1,6 @@
import Mixin from '@ember/object/mixin';
interface ClassNamesSupport {
- concatenatedProperties: string[];
classNames: string[];
classNameBindings: string[];
} | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/views/lib/mixins/view_support.d.ts | @@ -1,7 +1,6 @@
import Mixin from '@ember/object/mixin';
interface ViewSupport {
- concatenatedProperties: string[];
rerender(): unknown;
element: Element;
appendTo(selector: string | Element): this; | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/-internals/views/lib/views/core_view.ts | @@ -1,7 +1,6 @@
-import { View } from '@ember/-internals/glimmer/lib/renderer';
+import { Renderer, View } from '@ember/-internals/glimmer/lib/renderer';
import { inject } from '@ember/-internals/metal';
import { ActionHandler, Evented, FrameworkObject } from '@ember/-internals/runtime';
-import { CoreObjectClass } from '@ember/-internals/runtime/lib/system/core_object';
import states from './states';
/**
@@ -20,21 +19,17 @@ import states from './states';
@uses Ember.ActionHandler
@private
*/
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-interface CoreViewClass extends CoreObjectClass<CoreView> {}
-interface CoreView extends FrameworkObject, Evented, ActionHandler, View {}
-const CoreView = (FrameworkObject.extend(Evented, ActionHandler, {
- isView: true,
- _states: states,
+interface CoreView extends FrameworkObject, Evented, ActionHandler, View {}
+class CoreView extends FrameworkObject.extend(Evented, ActionHandler) {
+ isView = true;
- init() {
- this._super(...arguments);
- this._state = 'preRender';
- this._currentState = this._states.preRender;
- },
+ _states = states;
+ _state: unknown;
+ _currentState: unknown;
- renderer: inject('renderer', '-dom'),
+ _superTrigger?: Evented['trigger'];
+ _superHas?: Evented['has'];
/**
If the view is currently inserted into the DOM of a parent view, this
@@ -45,14 +40,32 @@ const CoreView = (FrameworkObject.extend(Evented, ActionHandler, {
@default null
@private
*/
- parentView: null,
+ declare parentView: View | null;
+
+ init(properties: object | undefined) {
+ super.init(properties);
+
+ // Handle methods from Evented
+ this._superTrigger = this.trigger;
+ this.trigger = this._trigger;
+ this._superHas = this.has;
+ this.has = this._has;
+
+ this.parentView ??= null;
+
+ this._state = 'preRender';
+ this._currentState = this._states.preRender;
+ }
+
+ @inject('renderer', '-dom')
+ declare renderer: Renderer;
instrumentDetails(hash: Record<string, unknown>) {
hash['object'] = this.toString();
hash['containerKey'] = this._debugContainerKey;
hash['view'] = this;
return hash;
- },
+ }
/**
Override the default event firing from `Evented` to
@@ -62,21 +75,21 @@ const CoreView = (FrameworkObject.extend(Evented, ActionHandler, {
@param name {String}
@private
*/
- trigger(name: string, ...args: any[]) {
- this._super(...arguments);
+ // Changed to `trigger` on init
+ _trigger(name: string, ...args: any[]) {
+ this._superTrigger!(name, ...args);
let method = this[name];
if (typeof method === 'function') {
return method.apply(this, args);
}
- },
+ }
- has(name: string) {
- return typeof this[name] === 'function' || this._super(name);
- },
-}) as unknown) as CoreViewClass;
+ // Changed to `has` on init
+ _has(name: string) {
+ return typeof this[name] === 'function' || this._superHas!(name);
+ }
-CoreView.reopenClass({
- isViewFactory: true,
-});
+ static isViewFactory = true;
+}
export default CoreView; | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/controller/lib/controller_mixin.d.ts | @@ -14,8 +14,6 @@ interface ControllerMixin<T> {
// From routing/lib/ext/controller
- concatenatedProperties: string[];
-
queryParams: Array<string | Record<string, { type: 'boolean' | 'number' | 'array' | 'string' }>>;
transitionToRoute(...args: RouteArgs<Route>): Transition; | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/controller/type-tests/index.test.ts | @@ -23,7 +23,7 @@ expectTypeOf(controller.target).toEqualTypeOf<unknown | undefined>();
expectTypeOf(controller.model).toEqualTypeOf<Foo>();
-expectTypeOf(controller.concatenatedProperties).toEqualTypeOf<string[]>();
+expectTypeOf(controller.concatenatedProperties).toEqualTypeOf<string[] | string | undefined>();
expectTypeOf(controller.queryParams).toEqualTypeOf<
Array<string | Record<string, { type: 'boolean' | 'number' | 'array' | 'string' }>> | true |
Other | emberjs | ember.js | ae6f8076c62a102caae6342a6910adb14590bc0e.json | Convert Object internals to TS | packages/@ember/object/type-tests/core/index.test.ts | @@ -10,18 +10,19 @@ expectTypeOf(CoreObject.create()).toEqualTypeOf<CoreObject>();
/** Newable tests */
const co1 = new CoreObject(owner);
-expectTypeOf(co1.concatenatedProperties).toEqualTypeOf<string[]>();
+expectTypeOf(co1.concatenatedProperties).toEqualTypeOf<string[] | string | undefined>();
expectTypeOf(co1.isDestroyed).toEqualTypeOf<boolean>();
expectTypeOf(co1.isDestroying).toEqualTypeOf<boolean>();
-expectTypeOf(co1.destroy()).toEqualTypeOf<void>();
+expectTypeOf(co1.destroy()).toEqualTypeOf<CoreObject>();
expectTypeOf(co1.toString()).toEqualTypeOf<string>();
/** .create tests */
+
const co2 = CoreObject.create();
-expectTypeOf(co2.concatenatedProperties).toEqualTypeOf<string[]>();
+expectTypeOf(co2.concatenatedProperties).toEqualTypeOf<string[] | string | undefined>();
expectTypeOf(co2.isDestroyed).toEqualTypeOf<boolean>();
expectTypeOf(co2.isDestroying).toEqualTypeOf<boolean>();
-expectTypeOf(co2.destroy()).toEqualTypeOf<void>();
+expectTypeOf(co2.destroy()).toEqualTypeOf<CoreObject>();
expectTypeOf(co2.toString()).toEqualTypeOf<string>();
/** .create tests w/ initial instance data passed in */ | true |
Other | emberjs | ember.js | a8d1dc6a7ba850c54b0c8e60503e50fed6c6ce02.json | tell eslint to ignore ts blueprint files | .eslintignore | @@ -1,4 +1,5 @@
blueprints/*/*files/**/*.js
+blueprints/*/*files/**/*.ts
node-tests/fixtures/**/*.js
/docs/
dist/ | false |
Other | emberjs | ember.js | 1ed27ae2527a1607264353c1aef1fb8d3295b32a.json | Add v4.3.0-beta.2 to CHANGELOG | CHANGELOG.md | @@ -1,5 +1,9 @@
# Ember Changelog
+### v4.3.0-beta.2 (March 1, 2022)
+
+- [#19971](https://github.com/emberjs/ember.js/pull/19971) [BUGFIX] Don't serialize default Query Params on RouterService
+
### v4.3.0-beta.1 (February 7, 2022)
No public API changes or bugfixes. | false |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | CHANGELOG.md | @@ -3144,7 +3144,7 @@ Clearly, `component-a` has subscribed to `some-other-component`'s `action`. Prev
* CollectionView context is now its content
* Various enhancements to bound helpers: adds multiple property support to bound helpers, adds bind-able options hash properties, adds {{unbound}} helper support to render unbound form of helpers.
* Add App.inject
-* Add Ember.EnumberableUtils.intersection
+* Add Ember.EnumerableUtils.intersection
* Deprecate Controller#controllerFor in favor of Controller#needs
* Adds `bubbles` property to Ember.TextField
* Allow overriding of Ember.Router#handleURL | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/container/lib/container.ts | @@ -308,15 +308,10 @@ function factoryFor(
return manager;
}
-interface FactoryOptions {
- instantiate?: boolean;
- singleton?: boolean;
-}
-
function isSingletonClass(
container: Container,
fullName: string,
- { instantiate, singleton }: FactoryOptions
+ { instantiate, singleton }: TypeOptions
) {
return (
singleton !== false &&
@@ -329,7 +324,7 @@ function isSingletonClass(
function isSingletonInstance(
container: Container,
fullName: string,
- { instantiate, singleton }: FactoryOptions
+ { instantiate, singleton }: TypeOptions
) {
return (
singleton !== false &&
@@ -342,7 +337,7 @@ function isSingletonInstance(
function isFactoryClass(
container: Container,
fullname: string,
- { instantiate, singleton }: FactoryOptions
+ { instantiate, singleton }: TypeOptions
) {
return (
instantiate === false &&
@@ -354,7 +349,7 @@ function isFactoryClass(
function isFactoryInstance(
container: Container,
fullName: string,
- { instantiate, singleton }: FactoryOptions
+ { instantiate, singleton }: TypeOptions
) {
return (
instantiate !== false &&
@@ -367,7 +362,7 @@ function instantiateFactory(
container: Container,
normalizedName: string,
fullName: string,
- options: FactoryOptions
+ options: TypeOptions
) {
let factoryManager = factoryFor(container, normalizedName, fullName);
| true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/container/lib/registry.ts | @@ -1,9 +1,9 @@
import { Factory } from '@ember/-internals/owner';
import { dictionary, intern } from '@ember/-internals/utils';
import { assert, deprecate } from '@ember/debug';
+import { set } from '@ember/object';
import { DEBUG } from '@glimmer/env';
import Container, { ContainerOptions, LazyInjection } from './container';
-
export interface Injection {
property: string;
specifier: string;
@@ -46,6 +46,10 @@ export type NotResolver = {
export type Resolve = <T, C>(name: string) => Factory<T, C> | undefined;
+export interface ResolverClass {
+ create(...args: unknown[]): Resolver;
+}
+
export interface Resolver {
knownForType?: (type: string) => KnownForTypeResult;
lookupDescription?: (fullName: string) => string;
@@ -77,7 +81,7 @@ const VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;
*/
export default class Registry implements IRegistry {
readonly _failSet: Set<string>;
- resolver: Resolver | (Resolve & NotResolver) | null;
+ resolver: Resolver | null;
readonly fallback: IRegistry | null;
readonly registrations: Record<string, object>;
_localLookupCache: Record<string, object>;
@@ -86,6 +90,8 @@ export default class Registry implements IRegistry {
readonly _resolveCache: Record<string, object>;
readonly _typeOptions: Record<string, TypeOptions>;
+ set?: typeof set;
+
constructor(options: RegistryOptions = {}) {
this.fallback = options.fallback || null;
this.resolver = options.resolver || null;
@@ -182,7 +188,9 @@ export default class Registry implements IRegistry {
@param {Function} factory
@param {Object} options
*/
- register(fullName: string, factory: Factory<unknown>, options: TypeOptions = {}): void {
+ register(fullName: string, factory: object, options: TypeOptions & { instantiate: false }): void;
+ register(fullName: string, factory: Factory<unknown>, options?: TypeOptions): void;
+ register(fullName: string, factory: object, options: TypeOptions = {}): void {
assert('fullName must be a proper full name', this.isValidFullName(fullName));
assert(`Attempting to register an unknown factory: '${fullName}'`, factory !== undefined);
| true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/metal/lib/property_get.ts | @@ -1,6 +1,7 @@
/**
@module @ember/object
*/
+import ProxyMixin from '@ember/-internals/runtime/lib/mixins/-proxy';
import { isEmberArray, setProxy, symbol } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
@@ -159,7 +160,7 @@ _getProp({ unknownProperty() {} }, 1 as any);
get({}, 'foo');
get({}, 'foo.bar');
-let fakeProxy = {};
+let fakeProxy = {} as ProxyMixin<unknown>;
setProxy(fakeProxy);
track(() => _getProp({}, 'a')); | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/-proxy.d.ts | @@ -0,0 +1,28 @@
+import { Mixin } from '@ember/-internals/metal';
+
+export function contentFor<T>(proxy: ProxyMixin<T>): T | null;
+
+interface ProxyMixin<T = unknown> {
+ /**
+ The object whose properties will be forwarded.
+
+ @property content
+ @type {unknown}
+ @default null
+ @public
+ */
+ content: T | null;
+
+ willDestroy(): void;
+
+ isTruthy: boolean;
+
+ unknownProperty<K extends keyof T>(key: K): T[K] | undefined;
+ unknownProperty(key: string): unknown;
+
+ setUnknownProperty<K extends keyof T>(key: K, value: T[K]): T[K];
+ setUnknownProperty<V>(key: string, value: V): V;
+}
+declare const ProxyMixin: Mixin;
+
+export default ProxyMixin; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/action_handler.d.ts | @@ -1,6 +1,9 @@
import { Mixin } from '@ember/-internals/metal';
-export default class ActionHandler extends Mixin {
+interface ActionHandler {
actions?: Record<string, (...args: any[]) => unknown>;
send(actionName: string, ...args: unknown[]): void;
}
+declare const ActionHandler: Mixin;
+
+export default ActionHandler; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/array.d.ts | @@ -1,8 +1,10 @@
import { Mixin } from '@ember/-internals/metal';
+import Enumerable from './enumerable';
+import MutableEnumerable from './mutable_enumerable';
type Value<T, K extends string> = K extends keyof T ? T[K] : unknown;
-interface EmberArray<T> {
+interface EmberArray<T> extends Enumerable {
length: number;
objectAt(idx: number): T | undefined;
objectsAt(indexes: number[]): Array<T | undefined>;
@@ -67,7 +69,7 @@ interface EmberArray<T> {
declare const EmberArray: Mixin;
export default EmberArray;
-interface MutableArray<T> extends EmberArray<T> {
+interface MutableArray<T> extends EmberArray<T>, MutableEnumerable {
replace(idx: number, amt: number, objects: T[]): void;
clear(): this;
insertAt(idx: number, object: T): this; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/array.js | @@ -1561,7 +1561,7 @@ const MutableArray = Mixin.create(ArrayMixin, MutableEnumerable, {
```
@method unshiftObjects
- @param {Enumberable} objects the objects to add
+ @param {Enumerable} objects the objects to add
@return {EmberArray} receiver
@public
*/ | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/container_proxy.d.ts | @@ -3,14 +3,14 @@ import { TypeOptions } from '@ember/-internals/container/lib/registry';
import { Mixin } from '@ember/-internals/metal';
import { Factory } from '@ember/-internals/owner';
-interface ContainerProxy {
+interface ContainerProxyMixin {
/** @internal */
__container__: Container;
ownerInjection(): void;
lookup(fullName: string, options?: TypeOptions): unknown;
factoryFor(fullName: string): Factory<unknown> | undefined;
}
-declare const ContainerProxy: Mixin;
+declare const ContainerProxyMixin: Mixin;
-export default ContainerProxy;
+export default ContainerProxyMixin; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/enumerable.d.ts | @@ -0,0 +1,7 @@
+import { Mixin } from '@ember/-internals/metal';
+
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+interface Enumerable {}
+declare const Enumerable: Mixin;
+
+export default Enumerable; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/mutable_enumerable.d.ts | @@ -0,0 +1,8 @@
+import { Mixin } from '@ember/-internals/metal';
+import Enumerable from './enumerable';
+
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+interface MutableEnumerable extends Enumerable {}
+declare const MutableEnumerable: Mixin;
+
+export default MutableEnumerable; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/mixins/promise_proxy.d.ts | @@ -0,0 +1,24 @@
+import { Mixin } from '@ember/-internals/metal';
+
+interface PromiseProxyMixin<T> {
+ reason: null;
+
+ readonly isPending: boolean;
+
+ readonly isSettled: boolean;
+
+ isRejected: boolean;
+
+ isFulfilled: boolean;
+
+ promise: Promise<T>;
+
+ then: this['promise']['then'];
+
+ catch: this['promise']['catch'];
+
+ finally: this['promise']['finally'];
+}
+declare const PromiseProxyMixin: Mixin;
+
+export default PromiseProxyMixin; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/system/core_object.d.ts | @@ -86,6 +86,7 @@ export default class CoreObject {
*/
isDestroying: boolean;
+ // NOTE That the actual CoreObject#destroy returns `this`;
/**
* Destroys an object by setting the `isDestroyed` flag and removing its
* metadata, which effectively destroys observers and bindings.
@@ -95,7 +96,7 @@ export default class CoreObject {
* happen immediately. It will set an isDestroying flag immediately.
* @return receiver
*/
- destroy(): CoreObject;
+ destroy(): void;
/**
* Override to implement teardown.
@@ -141,4 +142,7 @@ export default class CoreObject {
/** @internal */
static isMethod: boolean;
+
+ /** @internal */
+ static superclass: unknown;
} | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/runtime/lib/system/object_proxy.d.ts | @@ -0,0 +1,8 @@
+import FrameworkObject from './object';
+import _ProxyMixin from '../mixins/-proxy';
+
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+interface ObjectProxy extends _ProxyMixin {}
+declare class ObjectProxy extends FrameworkObject {}
+
+export default ObjectProxy; | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/-internals/utils/lib/is_proxy.ts | @@ -1,16 +1,17 @@
+import ProxyMixin from '@ember/-internals/runtime/lib/mixins/-proxy';
import { _WeakSet as WeakSet } from '@glimmer/util';
import { isObject } from './spec';
const PROXIES = new WeakSet();
-export function isProxy(value: any | undefined | null): value is object {
+export function isProxy(value: unknown): value is ProxyMixin<unknown> {
if (isObject(value)) {
return PROXIES.has(value);
}
return false;
}
-export function setProxy(object: object): void {
+export function setProxy(object: ProxyMixin<unknown>): void {
if (isObject(object)) {
PROXIES.add(object);
} | true |
Other | emberjs | ember.js | 2485aba0d858a5a13a4a5718d01b3a49de45dbf7.json | Add types for runtime mixins | packages/@ember/object/type-tests/core/index.test.ts | @@ -13,15 +13,15 @@ const co1 = new CoreObject(owner);
expectTypeOf(co1.concatenatedProperties).toEqualTypeOf<string[]>();
expectTypeOf(co1.isDestroyed).toEqualTypeOf<boolean>();
expectTypeOf(co1.isDestroying).toEqualTypeOf<boolean>();
-expectTypeOf(co1.destroy()).toEqualTypeOf<CoreObject>();
+expectTypeOf(co1.destroy()).toEqualTypeOf<void>();
expectTypeOf(co1.toString()).toEqualTypeOf<string>();
/** .create tests */
const co2 = CoreObject.create();
expectTypeOf(co2.concatenatedProperties).toEqualTypeOf<string[]>();
expectTypeOf(co2.isDestroyed).toEqualTypeOf<boolean>();
expectTypeOf(co2.isDestroying).toEqualTypeOf<boolean>();
-expectTypeOf(co2.destroy()).toEqualTypeOf<CoreObject>();
+expectTypeOf(co2.destroy()).toEqualTypeOf<void>();
expectTypeOf(co2.toString()).toEqualTypeOf<string>();
/** .create tests w/ initial instance data passed in */ | true |
Other | emberjs | ember.js | cd40a6be39e99664c13293a87c900ccb68f38d1c.json | Convert @ember/-internals/overrides to TS | packages/@ember/-internals/overrides/index.js | @@ -1 +0,0 @@
-export let onEmberGlobalAccess; | true |
Other | emberjs | ember.js | cd40a6be39e99664c13293a87c900ccb68f38d1c.json | Convert @ember/-internals/overrides to TS | packages/@ember/-internals/overrides/index.ts | @@ -0,0 +1 @@
+export let onEmberGlobalAccess: any; | true |
Other | emberjs | ember.js | 182a0345703e1456013b2206c414beaf7fb81caa.json | Avoid zebra classes for Component | packages/@ember/-internals/glimmer/lib/component.ts | @@ -1,6 +1,7 @@
import { get, PROPERTY_DID_CHANGE } from '@ember/-internals/metal';
-import { getOwner, Owner } from '@ember/-internals/owner';
+import { getOwner } from '@ember/-internals/owner';
import { TargetActionSupport } from '@ember/-internals/runtime';
+import { CoreObjectClass } from '@ember/-internals/runtime/lib/system/core_object';
import {
ActionSupport,
ChildViewsSupport,
@@ -26,7 +27,6 @@ import {
DIRTY_TAG,
IS_DISPATCHING_ATTRS,
} from './component-managers/curly';
-import { View } from './renderer';
// Keep track of which component classes have already been processed for lazy event setup.
let lazyEventsProcessed = new WeakMap<EventDispatcher, WeakSet<object>>();
@@ -649,6 +649,8 @@ let lazyEventsProcessed = new WeakMap<EventDispatcher, WeakSet<object>>();
@uses Ember.ViewStateSupport
@public
*/
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+interface ComponentClass extends CoreObjectClass<Component> {}
interface Component
extends CoreView,
ChildViewsSupport,
@@ -657,7 +659,7 @@ interface Component
TargetActionSupport,
ActionSupport,
ViewMixin {
- parentView: Component | null;
+ attributeBindings?: string[];
/**
Layout can be used to wrap content in a component.
@@ -677,403 +679,387 @@ interface Component
@private
*/
layoutName?: string;
-
- attributeBindings?: Array<string>;
}
-class Component
- extends CoreView.extend(
- ChildViewsSupport,
- ViewStateSupport,
- ClassNamesSupport,
- TargetActionSupport,
- ActionSupport,
- ViewMixin
- )
- implements View {
- static isComponentFactory = true;
- static positionalParams = [];
-
- static toString(): string {
- return '@ember/component';
- }
-
- isComponent = true;
-
- private __dispatcher: EventDispatcher | null | undefined;
- constructor(owner: Owner) {
- super(owner);
- this[IS_DISPATCHING_ATTRS] = false;
- this[DIRTY_TAG] = createTag();
- this[BOUNDS] = null;
-
- const eventDispatcher = this._dispatcher;
- if (eventDispatcher) {
- let lazyEventsProcessedForComponentClass = lazyEventsProcessed.get(eventDispatcher);
- if (!lazyEventsProcessedForComponentClass) {
- lazyEventsProcessedForComponentClass = new WeakSet<object>();
- lazyEventsProcessed.set(eventDispatcher, lazyEventsProcessedForComponentClass);
- }
+const Component = (CoreView.extend(
+ ChildViewsSupport,
+ ViewStateSupport,
+ ClassNamesSupport,
+ TargetActionSupport,
+ ActionSupport,
+ ViewMixin,
+ {
+ isComponent: true,
+
+ init() {
+ this._super(...arguments);
+ this[IS_DISPATCHING_ATTRS] = false;
+ this[DIRTY_TAG] = createTag();
+ this[BOUNDS] = null;
+
+ let eventDispatcher = this._dispatcher;
+ if (eventDispatcher) {
+ let lazyEventsProcessedForComponentClass = lazyEventsProcessed.get(eventDispatcher);
+ if (!lazyEventsProcessedForComponentClass) {
+ lazyEventsProcessedForComponentClass = new WeakSet<object>();
+ lazyEventsProcessed.set(eventDispatcher, lazyEventsProcessedForComponentClass);
+ }
- let proto = Object.getPrototypeOf(this);
- if (!lazyEventsProcessedForComponentClass.has(proto)) {
- let lazyEvents = eventDispatcher.lazyEvents;
+ let proto = Object.getPrototypeOf(this);
+ if (!lazyEventsProcessedForComponentClass.has(proto)) {
+ let lazyEvents = eventDispatcher.lazyEvents;
- lazyEvents.forEach((mappedEventName: string, event: string) => {
- if (mappedEventName !== null && typeof this[mappedEventName] === 'function') {
- eventDispatcher.setupHandlerForBrowserEvent(event);
- }
- });
+ lazyEvents.forEach((mappedEventName: string, event: string) => {
+ if (mappedEventName !== null && typeof this[mappedEventName] === 'function') {
+ eventDispatcher.setupHandlerForBrowserEvent(event);
+ }
+ });
- lazyEventsProcessedForComponentClass.add(proto);
+ lazyEventsProcessedForComponentClass.add(proto);
+ }
}
- }
- // @ts-expect-error _isInteractive is private
- if (DEBUG && eventDispatcher && this.renderer._isInteractive && this.tagName === '') {
- let eventNames = [];
- let events = eventDispatcher.finalEventNameMapping;
+ if (DEBUG && eventDispatcher && this.renderer._isInteractive && this.tagName === '') {
+ let eventNames = [];
+ let events = eventDispatcher.finalEventNameMapping;
- for (let key in events) {
- let methodName = events[key];
+ for (let key in events) {
+ let methodName = events[key];
- if (methodName && typeof this[methodName] === 'function') {
- eventNames.push(methodName);
+ if (typeof this[methodName] === 'function') {
+ eventNames.push(methodName);
+ }
}
- }
- // If in a tagless component, assert that no event handlers are defined
- assert(
- `You can not define \`${eventNames}\` function(s) to handle DOM event in the \`${this}\` tagless component since it doesn't have any DOM element.`,
- !eventNames.length
- );
- }
- }
-
- get _dispatcher(): EventDispatcher | null {
- if (this.__dispatcher === undefined) {
- let owner = getOwner(this);
- assert('Component is unexpectedly missing an owner', owner);
-
- if ((owner.lookup('-environment:main') as Environment)!.isInteractive) {
- let dispatcher = owner.lookup('event_dispatcher:main');
+ // If in a tagless component, assert that no event handlers are defined
assert(
- 'Expected dispatcher to be an EventDispatcher',
- dispatcher instanceof EventDispatcher
+ `You can not define \`${eventNames}\` function(s) to handle DOM event in the \`${this}\` tagless component since it doesn't have any DOM element.`,
+ !eventNames.length
);
- this.__dispatcher = dispatcher;
- } else {
- // In FastBoot we have no EventDispatcher. Set to null to not try again to look it up.
- this.__dispatcher = null;
}
- }
-
- return this.__dispatcher;
- }
-
- on<Target>(
- name: string,
- target: Target,
- method: string | ((this: Target, ...args: any[]) => void)
- ): this;
- on(name: string, method: ((...args: any[]) => void) | string): this;
- on<Target>(
- name: string,
- ...args:
- | [Target, string | ((this: Target, ...args: any[]) => void)]
- | [((...args: any[]) => void) | string]
- ): this {
- this._dispatcher?.setupHandlerForEmberEvent(name);
- return super.on(name, ...args);
- }
-
- rerender() {
- dirtyTag(this[DIRTY_TAG]);
- }
-
- [PROPERTY_DID_CHANGE](key: string, value?: unknown) {
- if (this[IS_DISPATCHING_ATTRS]) {
- return;
- }
-
- let args = this[ARGS];
- let reference = args !== undefined ? args[key] : undefined;
-
- if (reference !== undefined && isUpdatableRef(reference)) {
- updateRef(reference, arguments.length === 2 ? value : get(this, key));
- }
- }
-
- getAttr(key: string) {
- // TODO Intimate API should be deprecated
- return this.get(key);
- }
-
- /**
- Normally, Ember's component model is "write-only". The component takes a
- bunch of attributes that it got passed in, and uses them to render its
- template.
-
- One nice thing about this model is that if you try to set a value to the
- same thing as last time, Ember (through HTMLBars) will avoid doing any
- work on the DOM.
-
- This is not just a performance optimization. If an attribute has not
- changed, it is important not to clobber the element's "hidden state".
- For example, if you set an input's `value` to the same value as before,
- it will clobber selection state and cursor position. In other words,
- setting an attribute is not **always** idempotent.
-
- This method provides a way to read an element's attribute and also
- update the last value Ember knows about at the same time. This makes
- setting an attribute idempotent.
-
- In particular, what this means is that if you get an `<input>` element's
- `value` attribute and then re-render the template with the same value,
- it will avoid clobbering the cursor and selection position.
- Since most attribute sets are idempotent in the browser, you typically
- can get away with reading attributes using jQuery, but the most reliable
- way to do so is through this method.
- @method readDOMAttr
-
- @param {String} name the name of the attribute
- @return String
- @public
- */
- readDOMAttr(name: string) {
- // TODO revisit this
- let _element = getViewElement(this);
-
- assert(
- `Cannot call \`readDOMAttr\` on ${this} which does not have an element`,
- _element !== null
- );
-
- let element = _element;
- let isSVG = element.namespaceURI === Namespace.SVG;
- let { type, normalized } = normalizeProperty(element, name);
-
- if (isSVG || type === 'attr') {
- return element.getAttribute(normalized);
- }
-
- return element[normalized];
- }
-
- /**
- The WAI-ARIA role of the control represented by this view. For example, a
- button may have a role of type 'button', or a pane may have a role of
- type 'alertdialog'. This property is used by assistive software to help
- visually challenged users navigate rich web applications.
-
- The full list of valid WAI-ARIA roles is available at:
- [https://www.w3.org/TR/wai-aria/#roles_categorization](https://www.w3.org/TR/wai-aria/#roles_categorization)
-
- @property ariaRole
- @type String
- @default null
- @public
- */
-
- /**
- Enables components to take a list of parameters as arguments.
- For example, a component that takes two parameters with the names
- `name` and `age`:
-
- ```app/components/my-component.js
- import Component from '@ember/component';
-
- let MyComponent = Component.extend();
-
- MyComponent.reopenClass({
- positionalParams: ['name', 'age']
- });
-
- export default MyComponent;
- ```
-
- It can then be invoked like this:
-
- ```hbs
- {{my-component "John" 38}}
- ```
-
- The parameters can be referred to just like named parameters:
-
- ```hbs
- Name: {{name}}, Age: {{age}}.
- ```
-
- Using a string instead of an array allows for an arbitrary number of
- parameters:
-
- ```app/components/my-component.js
- import Component from '@ember/component';
-
- let MyComponent = Component.extend();
-
- MyComponent.reopenClass({
- positionalParams: 'names'
- });
-
- export default MyComponent;
- ```
-
- It can then be invoked like this:
-
- ```hbs
- {{my-component "John" "Michael" "Scott"}}
- ```
- The parameters can then be referred to by enumerating over the list:
-
- ```hbs
- {{#each names as |name|}}{{name}}{{/each}}
- ```
-
- @static
- @public
- @property positionalParams
- @since 1.13.0
- */
-
- /**
- Called when the attributes passed into the component have been updated.
- Called both during the initial render of a container and during a rerender.
- Can be used in place of an observer; code placed here will be executed
- every time any attribute updates.
- @method didReceiveAttrs
- @public
- @since 1.13.0
- */
- didReceiveAttrs() {}
+ },
+
+ get _dispatcher(): EventDispatcher | null {
+ if (this.__dispatcher === undefined) {
+ let owner = getOwner(this);
+ assert('Component is unexpectedly missing an owner', owner);
+
+ if ((owner.lookup('-environment:main') as Environment)!.isInteractive) {
+ this.__dispatcher = owner.lookup('event_dispatcher:main');
+ assert(
+ 'Expected dispatcher to be an EventDispatcher',
+ this.__dispatcher instanceof EventDispatcher
+ );
+ } else {
+ // In FastBoot we have no EventDispatcher. Set to null to not try again to look it up.
+ this.__dispatcher = null;
+ }
+ }
- /**
- Called when the attributes passed into the component have been updated.
- Called both during the initial render of a container and during a rerender.
- Can be used in place of an observer; code placed here will be executed
- every time any attribute updates.
- @event didReceiveAttrs
- @public
- @since 1.13.0
- */
+ return this.__dispatcher;
+ },
- /**
- Called after a component has been rendered, both on initial render and
- in subsequent rerenders.
- @method didRender
- @public
- @since 1.13.0
- */
- didRender() {}
+ on(eventName: string) {
+ this._dispatcher?.setupHandlerForEmberEvent(eventName);
+ return this._super(...arguments);
+ },
- /**
- Called after a component has been rendered, both on initial render and
- in subsequent rerenders.
- @event didRender
- @public
- @since 1.13.0
- */
+ rerender() {
+ dirtyTag(this[DIRTY_TAG]);
+ this._super();
+ },
- /**
- Called before a component has been rendered, both on initial render and
- in subsequent rerenders.
- @method willRender
- @public
- @since 1.13.0
- */
- willRender() {}
+ [PROPERTY_DID_CHANGE](key: string, value?: unknown) {
+ if (this[IS_DISPATCHING_ATTRS]) {
+ return;
+ }
- /**
- Called before a component has been rendered, both on initial render and
- in subsequent rerenders.
- @event willRender
- @public
- @since 1.13.0
- */
+ let args = this[ARGS];
+ let reference = args !== undefined ? args[key] : undefined;
- /**
- Called when the attributes passed into the component have been changed.
- Called only during a rerender, not during an initial render.
- @method didUpdateAttrs
- @public
- @since 1.13.0
- */
- didUpdateAttrs() {}
+ if (reference !== undefined && isUpdatableRef(reference)) {
+ updateRef(reference, arguments.length === 2 ? value : get(this, key));
+ }
+ },
+
+ getAttr(key: string) {
+ // TODO Intimate API should be deprecated
+ return this.get(key);
+ },
+
+ /**
+ Normally, Ember's component model is "write-only". The component takes a
+ bunch of attributes that it got passed in, and uses them to render its
+ template.
+
+ One nice thing about this model is that if you try to set a value to the
+ same thing as last time, Ember (through HTMLBars) will avoid doing any
+ work on the DOM.
+
+ This is not just a performance optimization. If an attribute has not
+ changed, it is important not to clobber the element's "hidden state".
+ For example, if you set an input's `value` to the same value as before,
+ it will clobber selection state and cursor position. In other words,
+ setting an attribute is not **always** idempotent.
+
+ This method provides a way to read an element's attribute and also
+ update the last value Ember knows about at the same time. This makes
+ setting an attribute idempotent.
+
+ In particular, what this means is that if you get an `<input>` element's
+ `value` attribute and then re-render the template with the same value,
+ it will avoid clobbering the cursor and selection position.
+ Since most attribute sets are idempotent in the browser, you typically
+ can get away with reading attributes using jQuery, but the most reliable
+ way to do so is through this method.
+ @method readDOMAttr
+
+ @param {String} name the name of the attribute
+ @return String
+ @public
+ */
+ readDOMAttr(name: string) {
+ // TODO revisit this
+ let _element = getViewElement(this);
- /**
- Called when the attributes passed into the component have been changed.
- Called only during a rerender, not during an initial render.
- @event didUpdateAttrs
- @public
- @since 1.13.0
- */
+ assert(
+ `Cannot call \`readDOMAttr\` on ${this} which does not have an element`,
+ _element !== null
+ );
- /**
- Called when the component is about to update and rerender itself.
- Called only during a rerender, not during an initial render.
- @method willUpdate
- @public
- @since 1.13.0
- */
- willUpdate() {}
+ let element = _element;
+ let isSVG = element.namespaceURI === Namespace.SVG;
+ let { type, normalized } = normalizeProperty(element, name);
- /**
- Called when the component is about to update and rerender itself.
- Called only during a rerender, not during an initial render.
- @event willUpdate
- @public
- @since 1.13.0
- */
+ if (isSVG || type === 'attr') {
+ return element.getAttribute(normalized);
+ }
- /**
- Called when the component has updated and rerendered itself.
- Called only during a rerender, not during an initial render.
- @method didUpdate
- @public
- @since 1.13.0
- */
- didUpdate() {}
+ return element[normalized];
+ },
+
+ /**
+ The WAI-ARIA role of the control represented by this view. For example, a
+ button may have a role of type 'button', or a pane may have a role of
+ type 'alertdialog'. This property is used by assistive software to help
+ visually challenged users navigate rich web applications.
+
+ The full list of valid WAI-ARIA roles is available at:
+ [https://www.w3.org/TR/wai-aria/#roles_categorization](https://www.w3.org/TR/wai-aria/#roles_categorization)
+
+ @property ariaRole
+ @type String
+ @default null
+ @public
+ */
+
+ /**
+ Enables components to take a list of parameters as arguments.
+ For example, a component that takes two parameters with the names
+ `name` and `age`:
+
+ ```app/components/my-component.js
+ import Component from '@ember/component';
+
+ let MyComponent = Component.extend();
+
+ MyComponent.reopenClass({
+ positionalParams: ['name', 'age']
+ });
+
+ export default MyComponent;
+ ```
+
+ It can then be invoked like this:
+
+ ```hbs
+ {{my-component "John" 38}}
+ ```
+
+ The parameters can be referred to just like named parameters:
+
+ ```hbs
+ Name: {{name}}, Age: {{age}}.
+ ```
+
+ Using a string instead of an array allows for an arbitrary number of
+ parameters:
+
+ ```app/components/my-component.js
+ import Component from '@ember/component';
+
+ let MyComponent = Component.extend();
+
+ MyComponent.reopenClass({
+ positionalParams: 'names'
+ });
+
+ export default MyComponent;
+ ```
+
+ It can then be invoked like this:
+
+ ```hbs
+ {{my-component "John" "Michael" "Scott"}}
+ ```
+ The parameters can then be referred to by enumerating over the list:
+
+ ```hbs
+ {{#each names as |name|}}{{name}}{{/each}}
+ ```
+
+ @static
+ @public
+ @property positionalParams
+ @since 1.13.0
+ */
+
+ /**
+ Called when the attributes passed into the component have been updated.
+ Called both during the initial render of a container and during a rerender.
+ Can be used in place of an observer; code placed here will be executed
+ every time any attribute updates.
+ @method didReceiveAttrs
+ @public
+ @since 1.13.0
+ */
+ didReceiveAttrs() {},
+
+ /**
+ Called when the attributes passed into the component have been updated.
+ Called both during the initial render of a container and during a rerender.
+ Can be used in place of an observer; code placed here will be executed
+ every time any attribute updates.
+ @event didReceiveAttrs
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called after a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @method didRender
+ @public
+ @since 1.13.0
+ */
+ didRender() {},
+
+ /**
+ Called after a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @event didRender
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called before a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @method willRender
+ @public
+ @since 1.13.0
+ */
+ willRender() {},
+
+ /**
+ Called before a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @event willRender
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the attributes passed into the component have been changed.
+ Called only during a rerender, not during an initial render.
+ @method didUpdateAttrs
+ @public
+ @since 1.13.0
+ */
+ didUpdateAttrs() {},
+
+ /**
+ Called when the attributes passed into the component have been changed.
+ Called only during a rerender, not during an initial render.
+ @event didUpdateAttrs
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the component is about to update and rerender itself.
+ Called only during a rerender, not during an initial render.
+ @method willUpdate
+ @public
+ @since 1.13.0
+ */
+ willUpdate() {},
+
+ /**
+ Called when the component is about to update and rerender itself.
+ Called only during a rerender, not during an initial render.
+ @event willUpdate
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the component has updated and rerendered itself.
+ Called only during a rerender, not during an initial render.
+ @method didUpdate
+ @public
+ @since 1.13.0
+ */
+ didUpdate() {},
+
+ /**
+ Called when the component has updated and rerendered itself.
+ Called only during a rerender, not during an initial render.
+ @event didUpdate
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ The HTML `id` of the component's element in the DOM. You can provide this
+ value yourself but it must be unique (just as in HTML):
+
+ ```handlebars
+ {{my-component elementId="a-really-cool-id"}}
+ ```
+
+ ```handlebars
+ <MyComponent @elementId="a-really-cool-id" />
+ ```
+ If not manually set a default value will be provided by the framework.
+ Once rendered an element's `elementId` is considered immutable and you
+ should never change it. If you need to compute a dynamic value for the
+ `elementId`, you should do this when the component or element is being
+ instantiated:
+
+ ```javascript
+ export default Component.extend({
+ init() {
+ this._super(...arguments);
+
+ var index = this.get('index');
+ this.set('elementId', `component-id${index}`);
+ }
+ });
+ ```
- /**
- Called when the component has updated and rerendered itself.
- Called only during a rerender, not during an initial render.
- @event didUpdate
- @public
- @since 1.13.0
+ @property elementId
+ @type String
+ @public
*/
+ }
+) as unknown) as ComponentClass;
- /**
- The HTML `id` of the component's element in the DOM. You can provide this
- value yourself but it must be unique (just as in HTML):
-
- ```handlebars
- {{my-component elementId="a-really-cool-id"}}
- ```
-
- ```handlebars
- <MyComponent @elementId="a-really-cool-id" />
- ```
- If not manually set a default value will be provided by the framework.
- Once rendered an element's `elementId` is considered immutable and you
- should never change it. If you need to compute a dynamic value for the
- `elementId`, you should do this when the component or element is being
- instantiated:
-
- ```javascript
- export default Component.extend({
- init() {
- this._super(...arguments);
-
- var index = this.get('index');
- this.set('elementId', `component-id${index}`);
- }
- });
- ```
+Component.toString = () => '@ember/component';
- @property elementId
- @type String
- @public
- */
-}
+Component.reopenClass({
+ isComponentFactory: true,
+ positionalParams: [],
+});
setInternalComponentManager(CURLY_COMPONENT_MANAGER, Component);
| true |
Other | emberjs | ember.js | 182a0345703e1456013b2206c414beaf7fb81caa.json | Avoid zebra classes for Component | packages/@ember/-internals/runtime/lib/mixins/action_handler.d.ts | @@ -1,3 +1,6 @@
import { Mixin } from '@ember/-internals/metal';
-export default class ActionHandler extends Mixin {}
+export default class ActionHandler extends Mixin {
+ actions?: Record<string, (...args: unknown[]) => void>;
+ send(actionName: string, ...args: unknown[]): void;
+} | true |
Other | emberjs | ember.js | 182a0345703e1456013b2206c414beaf7fb81caa.json | Avoid zebra classes for Component | packages/@ember/-internals/runtime/lib/system/core_object.d.ts | @@ -11,18 +11,39 @@ import { Owner } from '@ember/-internals/owner';
* Implementation is carefully chosen for the reasons described in
* https://github.com/typed-ember/ember-typings/pull/29
*/
-type EmberClassConstructor<T> = new (owner: Owner) => T;
+export type EmberClassConstructor<T> = new (owner: Owner) => T;
-type MergeArray<Arr extends any[]> = Arr extends [infer T, ...infer Rest]
+export type MergeArray<Arr extends any[]> = Arr extends [infer T, ...infer Rest]
? T & MergeArray<Rest>
: unknown; // TODO: Is this correct?
+/** @internal */
+export interface CoreObjectClass<Instance> extends EmberClassConstructor<Instance> {
+ /** @internal */
+ extend<Statics>(
+ this: EmberClassConstructor<Instance>,
+ ...args: any[]
+ ): CoreObjectClass<Statics & Instance>;
+
+ /** @internal */
+ reopen(...args: any[]): any;
+
+ /** @internal */
+ reopenClass(...args: any[]): any;
+
+ /** @internal */
+ create<Class extends EmberClassConstructor<Instance>, Args extends Array<Record<string, any>>>(
+ this: Class,
+ ...args: Args
+ ): InstanceType<Class> & MergeArray<Args>;
+}
+
export default class CoreObject {
/** @internal */
static extend<Statics, Instance>(
this: Statics & EmberClassConstructor<Instance>,
...args: any[]
- ): Readonly<Statics> & EmberClassConstructor<Instance>;
+ ): Readonly<Statics> & CoreObjectClass<Instance>;
/** @internal */
static reopen(...args: any[]): any; | true |
Other | emberjs | ember.js | 182a0345703e1456013b2206c414beaf7fb81caa.json | Avoid zebra classes for Component | packages/@ember/-internals/views/lib/views/core_view.d.ts | @@ -1,12 +0,0 @@
-import { Renderer } from '@ember/-internals/glimmer';
-import { ActionHandler } from '@ember/-internals/runtime';
-import EmberObject from '@ember/object';
-import Evented from '@ember/object/evented';
-
-interface CoreView extends Evented, ActionHandler {}
-declare class CoreView extends EmberObject {
- parentView: CoreView | null;
- renderer: Renderer;
-}
-
-export { CoreView as default }; | true |
Other | emberjs | ember.js | 182a0345703e1456013b2206c414beaf7fb81caa.json | Avoid zebra classes for Component | packages/@ember/-internals/views/lib/views/core_view.ts | @@ -1,5 +1,7 @@
+import { View } from '@ember/-internals/glimmer/lib/renderer';
import { inject } from '@ember/-internals/metal';
import { ActionHandler, Evented, FrameworkObject } from '@ember/-internals/runtime';
+import { CoreObjectClass } from '@ember/-internals/runtime/lib/system/core_object';
import states from './states';
/**
@@ -18,7 +20,10 @@ import states from './states';
@uses Ember.ActionHandler
@private
*/
-const CoreView = FrameworkObject.extend(Evented, ActionHandler, {
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+interface CoreViewClass extends CoreObjectClass<CoreView> {}
+interface CoreView extends FrameworkObject, Evented, ActionHandler, View {}
+const CoreView = (FrameworkObject.extend(Evented, ActionHandler, {
isView: true,
_states: states,
@@ -42,7 +47,7 @@ const CoreView = FrameworkObject.extend(Evented, ActionHandler, {
*/
parentView: null,
- instrumentDetails(hash) {
+ instrumentDetails(hash: any) {
hash.object = this.toString();
hash.containerKey = this._debugContainerKey;
hash.view = this;
@@ -57,18 +62,18 @@ const CoreView = FrameworkObject.extend(Evented, ActionHandler, {
@param name {String}
@private
*/
- trigger(name, ...args) {
+ trigger(name: string, ...args: any[]) {
this._super(...arguments);
let method = this[name];
if (typeof method === 'function') {
return method.apply(this, args);
}
},
- has(name) {
+ has(name: string) {
return typeof this[name] === 'function' || this._super(name);
},
-});
+}) as unknown) as CoreViewClass;
CoreView.reopenClass({
isViewFactory: true, | true |
Other | emberjs | ember.js | 182a0345703e1456013b2206c414beaf7fb81caa.json | Avoid zebra classes for Component | packages/@ember/component/type-tests/index.test.ts | @@ -1,51 +1,16 @@
import Component from '@ember/component';
import { CoreView } from '@ember/-internals/views';
import { expectTypeOf } from 'expect-type';
-import { Owner } from '@ember/-internals/owner';
import { View } from '@ember/-internals/glimmer/lib/renderer';
-import { action } from '@ember/object';
-import { tracked } from '@ember/-internals/metal';
-// NOTE: This is invalid, but acceptable for type tests
-let owner = {} as Owner;
-let component = new Component(owner);
+const MyComponent = Component.extend();
+
+let component = MyComponent.create();
expectTypeOf(component).toMatchTypeOf<CoreView>();
expectTypeOf(component).toMatchTypeOf<View>();
-class MyComponent extends Component {
- tagName = 'em';
- classNames = ['my-class', 'my-other-class'];
- classNameBindings = ['propertyA', 'propertyB'];
- attributeBindings = ['href'];
-
- @tracked propertyA = 'from-a';
-
- get propertyB(): string | void {
- if (this.propertyA === 'from-a') {
- return 'from-b';
- }
- }
-
- @tracked href = 'https://tilde.io';
-
- @action click(_event: Event): void {
- // Clicked!
- }
-}
-new MyComponent(owner);
-
-class BadComponent extends Component {
- // @ts-expect-error invalid tag name
- tagName = 1;
-
- // @ts-expect-error invalid classname
- classNames = 'foo';
-
- // @ts-expect-error invalid classNameBindings
- classNameBindings = [1];
-
- // @ts-expect-error invalid attributeBindings
- attributeBindings = [true];
-}
-new BadComponent(owner);
+expectTypeOf(component.tagName).toEqualTypeOf<string | null>();
+expectTypeOf(component.classNames).toEqualTypeOf<string[]>();
+expectTypeOf(component.classNameBindings).toEqualTypeOf<string[]>();
+expectTypeOf(component.attributeBindings).toEqualTypeOf<string[] | undefined>(); | true |
Other | emberjs | ember.js | 182a0345703e1456013b2206c414beaf7fb81caa.json | Avoid zebra classes for Component | packages/@ember/helper/type-tests/invoke-helper.test.ts | @@ -1,6 +1,5 @@
import Component from '@ember/-internals/glimmer/lib/component';
import { getValue } from '@ember/-internals/metal';
-import { Owner } from '@ember/-internals/owner';
import Helper from '@ember/component/helper';
import { invokeHelper } from '@ember/helper';
import { Cache } from '@glimmer/validator';
@@ -14,7 +13,7 @@ class PlusOne extends Helper {
}
}
-export default class PlusOneComponent extends Component {
+class PlusOneComponent extends Component {
// Glint would help with this
declare args: { number: number };
@@ -29,8 +28,6 @@ export default class PlusOneComponent extends Component {
}
}
-// Good enough for tests!
-let owner = {} as Owner;
-let component = new PlusOneComponent(owner);
+let component = PlusOneComponent.create();
expectTypeOf(component.plusOne).toEqualTypeOf<Cache<unknown>>(); | true |
Other | emberjs | ember.js | 2313c5c28fbb1cea4b8793c06cdc58b14ece3332.json | Add a feature flag for the unique-id helper | packages/@ember/-internals/glimmer/lib/resolver.ts | @@ -2,6 +2,7 @@ import { privatize as P } from '@ember/-internals/container';
import { TypeOptions } from '@ember/-internals/container/lib/registry';
import { ENV } from '@ember/-internals/environment';
import { Factory, Owner } from '@ember/-internals/owner';
+import { EMBER_UNIQUE_ID_HELPER } from '@ember/canary-features';
import { assert } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { DEBUG } from '@glimmer/env';
@@ -144,9 +145,12 @@ const BUILTIN_HELPERS = {
fn,
get,
hash,
- 'unique-id': uniqueId,
};
+if (EMBER_UNIQUE_ID_HELPER) {
+ BUILTIN_HELPERS['unique-id'] = uniqueId;
+}
+
const BUILTIN_KEYWORD_MODIFIERS = {
action: actionModifier,
}; | true |
Other | emberjs | ember.js | 2313c5c28fbb1cea4b8793c06cdc58b14ece3332.json | Add a feature flag for the unique-id helper | packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js | @@ -1,144 +1,147 @@
import { RenderingTestCase, strip, moduleFor, runTask } from 'internal-test-helpers';
import { setProperties } from '@ember/-internals/metal';
-
-moduleFor(
- 'Helpers test: {{unique-id}}',
- class extends RenderingTestCase {
- ['@test it generates a unique id (string) each time']() {
- let { first, second } = this.render(`<p>{{unique-id}}</p><p>{{unique-id}}</p>`, () => {
- let first = this.asElement(this.firstChild);
- let second = this.asElement(this.nthChild(1));
-
- return {
- first: this.asTextContent(first.firstChild),
- second: this.asTextContent(second.firstChild),
- };
- });
-
- this.assert.notStrictEqual(
- first,
- second,
- `different invocations of {{unique-id}} should produce different values`
- );
- }
-
- [`@test when unique-id is used with #let, it remains stable when it's used`]() {
- let { first, second } = this.render(
- strip`
- {{#let (unique-id) as |id|}}
- <p>{{id}}</p><p>{{id}}</p>
- {{/let}}
- `,
- () => {
+import { EMBER_UNIQUE_ID_HELPER } from '@ember/canary-features';
+
+if (EMBER_UNIQUE_ID_HELPER) {
+ moduleFor(
+ 'Helpers test: {{unique-id}}',
+ class extends RenderingTestCase {
+ ['@test it generates a unique id (string) each time']() {
+ let { first, second } = this.render(`<p>{{unique-id}}</p><p>{{unique-id}}</p>`, () => {
let first = this.asElement(this.firstChild);
let second = this.asElement(this.nthChild(1));
return {
first: this.asTextContent(first.firstChild),
second: this.asTextContent(second.firstChild),
};
- }
- );
+ });
- this.assert.strictEqual(
- first,
- second,
- `when unique-id is used as a variable, it remains the same`
- );
- }
+ this.assert.notStrictEqual(
+ first,
+ second,
+ `different invocations of {{unique-id}} should produce different values`
+ );
+ }
- [`@test unique-id doesn't change if it's concatenated with a value that does change`]() {
- class Elements {
- constructor(label, input, assert) {
- this.label = label;
- this.input = input;
- this.assert = assert;
- }
+ [`@test when unique-id is used with #let, it remains stable when it's used`]() {
+ let { first, second } = this.render(
+ strip`
+ {{#let (unique-id) as |id|}}
+ <p>{{id}}</p><p>{{id}}</p>
+ {{/let}}
+ `,
+ () => {
+ let first = this.asElement(this.firstChild);
+ let second = this.asElement(this.nthChild(1));
+
+ return {
+ first: this.asTextContent(first.firstChild),
+ second: this.asTextContent(second.firstChild),
+ };
+ }
+ );
- id(regex) {
- let forAttr = this.label.getAttribute('for');
+ this.assert.strictEqual(
+ first,
+ second,
+ `when unique-id is used as a variable, it remains the same`
+ );
+ }
- this.assert.strictEqual(
- forAttr,
- this.input.getAttribute('id'),
- `the label's 'for' attribute should be the same as the input's 'id' attribute`
- );
+ [`@test unique-id doesn't change if it's concatenated with a value that does change`]() {
+ class Elements {
+ constructor(label, input, assert) {
+ this.label = label;
+ this.input = input;
+ this.assert = assert;
+ }
- let match = forAttr.match(regex);
+ id(regex) {
+ let forAttr = this.label.getAttribute('for');
- this.assert.ok(match, 'the id starts with the prefix');
+ this.assert.strictEqual(
+ forAttr,
+ this.input.getAttribute('id'),
+ `the label's 'for' attribute should be the same as the input's 'id' attribute`
+ );
- return match[1];
+ let match = forAttr.match(regex);
+
+ this.assert.ok(match, 'the id starts with the prefix');
+
+ return match[1];
+ }
}
- }
- let { elements, id } = this.render(
- strip`
+ let { elements, id } = this.render(
+ strip`
{{#let (unique-id) as |id|}}
<label for="{{this.prefix}}-{{id}}">Enable Feature</label>
<input id="{{this.prefix}}-{{id}}" type="checkbox">
{{/let}}`,
- { prefix: 'app' },
- () => {
- let label = this.asElement(this.firstChild, 'label');
- let input = this.asElement(this.nthChild(1), 'input');
-
- let elements = new Elements(label, input, this.assert);
-
- return { elements, id: elements.id(/^app-(.*)$/) };
- }
- );
+ { prefix: 'app' },
+ () => {
+ let label = this.asElement(this.firstChild, 'label');
+ let input = this.asElement(this.nthChild(1), 'input');
- this.update({ prefix: 'melanie' }, () => {
- let newId = elements.id(/^melanie-(.*)$/);
+ let elements = new Elements(label, input, this.assert);
- this.assert.strictEqual(
- id,
- newId,
- `the unique-id part of a concatenated attribute shouldn't change just because a dynamic part of it changed`
+ return { elements, id: elements.id(/^app-(.*)$/) };
+ }
);
- });
- }
- render(template, ...rest) {
- // If there are three parameters to `render`, the second parameter is the
- // template's arguments.
- let args = rest.length === 2 ? rest[0] : {};
- // If there are two parameters to `render`, the second parameter is the
- // postcondition. Otherwise, the third parameter is the postcondition.
- let postcondition = rest.length === 2 ? rest[1] : rest[0];
-
- super.render(template, args);
- let result = postcondition();
- this.assertStableRerender();
- return result;
- }
+ this.update({ prefix: 'melanie' }, () => {
+ let newId = elements.id(/^melanie-(.*)$/);
- update(args, postcondition) {
- runTask(() => setProperties(this.context, args));
- postcondition();
- this.assertStableRerender();
- }
+ this.assert.strictEqual(
+ id,
+ newId,
+ `the unique-id part of a concatenated attribute shouldn't change just because a dynamic part of it changed`
+ );
+ });
+ }
- asElement(node, tag) {
- this.assert.ok(node !== null && node.nodeType === 1);
+ render(template, ...rest) {
+ // If there are three parameters to `render`, the second parameter is the
+ // template's arguments.
+ let args = rest.length === 2 ? rest[0] : {};
+ // If there are two parameters to `render`, the second parameter is the
+ // postcondition. Otherwise, the third parameter is the postcondition.
+ let postcondition = rest.length === 2 ? rest[1] : rest[0];
+
+ super.render(template, args);
+ let result = postcondition();
+ this.assertStableRerender();
+ return result;
+ }
- if (tag) {
- this.assert.strictEqual(node.tagName.toLowerCase(), tag, `Element is <${tag}>`);
+ update(args, postcondition) {
+ runTask(() => setProperties(this.context, args));
+ postcondition();
+ this.assertStableRerender();
}
- return node;
- }
+ asElement(node, tag) {
+ this.assert.ok(node !== null && node.nodeType === 1);
- asTextNode(node) {
- this.assert.ok(node !== null && node.nodeType === 3);
- return node;
- }
+ if (tag) {
+ this.assert.strictEqual(node.tagName.toLowerCase(), tag, `Element is <${tag}>`);
+ }
- asTextContent(node) {
- let data = this.asTextNode(node).data;
- this.assert.ok(data.trim().length > 0, `The text node has content`);
- return data;
+ return node;
+ }
+
+ asTextNode(node) {
+ this.assert.ok(node !== null && node.nodeType === 3);
+ return node;
+ }
+
+ asTextContent(node) {
+ let data = this.asTextNode(node).data;
+ this.assert.ok(data.trim().length > 0, `The text node has content`);
+ return data;
+ }
}
- }
-);
+ );
+} | true |
Other | emberjs | ember.js | 2313c5c28fbb1cea4b8793c06cdc58b14ece3332.json | Add a feature flag for the unique-id helper | packages/@ember/canary-features/index.ts | @@ -16,6 +16,7 @@ export const DEFAULT_FEATURES = {
EMBER_IMPROVED_INSTRUMENTATION: null,
EMBER_ROUTING_ROUTER_SERVICE_REFRESH: true,
EMBER_CACHED: true,
+ EMBER_UNIQUE_ID_HELPER: null,
};
/**
@@ -70,3 +71,4 @@ export const EMBER_ROUTING_ROUTER_SERVICE_REFRESH = featureValue(
FEATURES.EMBER_ROUTING_ROUTER_SERVICE_REFRESH
);
export const EMBER_CACHED = featureValue(FEATURES.EMBER_CACHED);
+export const EMBER_UNIQUE_ID_HELPER = featureValue(FEATURES.EMBER_UNIQUE_ID_HELPER); | true |
Other | emberjs | ember.js | aa8c53aa45aa7d2e7badfee1207d9dd4f4196fc2.json | Add type-tests for @ember/version | packages/@ember/version/type-tests/index.test.ts | @@ -0,0 +1,4 @@
+import { VERSION } from '@ember/version';
+import { expectTypeOf } from 'expect-type';
+
+expectTypeOf(VERSION).toEqualTypeOf<string>(); | false |
Other | emberjs | ember.js | 420a01fe1864a5e8d447ac714a3cfb9aff012a49.json | Improve @ember/utils and add type tests | packages/@ember/-internals/metal/lib/is_blank.ts | @@ -8,7 +8,6 @@ import isEmpty from './is_empty';
```javascript
import { isBlank } from '@ember/utils';
- isBlank(); // true
isBlank(null); // true
isBlank(undefined); // true
isBlank(''); // true
@@ -29,6 +28,6 @@ import isEmpty from './is_empty';
@since 1.5.0
@public
*/
-export default function isBlank(obj: any): boolean {
+export default function isBlank(obj: unknown): boolean {
return isEmpty(obj) || (typeof obj === 'string' && /\S/.test(obj) === false);
} | true |
Other | emberjs | ember.js | 420a01fe1864a5e8d447ac714a3cfb9aff012a49.json | Improve @ember/utils and add type tests | packages/@ember/-internals/metal/lib/is_empty.ts | @@ -1,4 +1,4 @@
-import { get } from './property_get';
+import { get, MaybeHasUnknownProperty } from './property_get';
/**
@module @ember/utils
*/
@@ -13,7 +13,6 @@ import { get } from './property_get';
to check emptiness.
```javascript
- isEmpty(); // true
isEmpty(null); // true
isEmpty(undefined); // true
isEmpty(''); // true
@@ -35,33 +34,40 @@ import { get } from './property_get';
@return {Boolean}
@public
*/
-export default function isEmpty(obj: any): boolean {
- let none = obj === null || obj === undefined;
- if (none) {
- return none;
+export default function isEmpty(obj: unknown): boolean {
+ if (obj === null || obj === undefined) {
+ return true;
}
- if (typeof obj.unknownProperty !== 'function' && typeof obj.size === 'number') {
- return !obj.size;
+ if (
+ typeof (obj as MaybeHasUnknownProperty).unknownProperty !== 'function' &&
+ typeof (obj as HasSize).size === 'number'
+ ) {
+ return !(obj as HasSize).size;
}
- let objectType = typeof obj;
-
- if (objectType === 'object') {
+ if (typeof obj === 'object') {
let size = get(obj, 'size');
if (typeof size === 'number') {
return !size;
}
-
let length = get(obj, 'length');
if (typeof length === 'number') {
return !length;
}
}
- if (typeof obj.length === 'number' && objectType !== 'function') {
- return !obj.length;
+ if (typeof (obj as HasLength).length === 'number' && typeof obj !== 'function') {
+ return !(obj as HasLength).length;
}
return false;
}
+
+interface HasSize {
+ size: number;
+}
+
+interface HasLength {
+ length: number;
+} | true |
Other | emberjs | ember.js | 420a01fe1864a5e8d447ac714a3cfb9aff012a49.json | Improve @ember/utils and add type tests | packages/@ember/-internals/metal/lib/is_none.ts | @@ -7,7 +7,6 @@
confusing.
```javascript
- isNone(); // true
isNone(null); // true
isNone(undefined); // true
isNone(''); // false | true |
Other | emberjs | ember.js | 420a01fe1864a5e8d447ac714a3cfb9aff012a49.json | Improve @ember/utils and add type tests | packages/@ember/-internals/metal/lib/is_present.ts | @@ -6,7 +6,6 @@ import isBlank from './is_blank';
A value is present if it not `isBlank`.
```javascript
- isPresent(); // false
isPresent(null); // false
isPresent(undefined); // false
isPresent(''); // false
@@ -32,6 +31,6 @@ import isBlank from './is_blank';
@since 1.8.0
@public
*/
-export default function isPresent(obj: object): boolean {
+export default function isPresent<T>(obj: T): obj is Exclude<T, null | undefined> {
return !isBlank(obj);
} | true |
Other | emberjs | ember.js | 420a01fe1864a5e8d447ac714a3cfb9aff012a49.json | Improve @ember/utils and add type tests | packages/@ember/-internals/metal/lib/property_get.ts | @@ -23,7 +23,7 @@ if (DEBUG) {
};
}
-interface MaybeHasUnknownProperty {
+export interface MaybeHasUnknownProperty {
unknownProperty?: (keyName: string) => any;
}
| true |