Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: event communication #2554

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ember_debug/adapters/web-extension.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BasicAdapter from './basic';
import { typeOf } from 'ember-debug/utils/type-check';

import Ember from 'ember-debug/utils/ember';
import { ember } from 'ember-debug/utils/ember';
import { run } from 'ember-debug/utils/ember/runloop';

const { isArray } = Array;
Expand Down Expand Up @@ -105,7 +105,7 @@ export default class extends BasicAdapter {
// adapter later. See GH #1114.
const HAS_ARRAY_PROTOTYPE_EXTENSIONS = (() => {
try {
return Ember.ENV.EXTEND_PROTOTYPES.Array === true;
return ember.env.EXTEND_PROTOTYPES.Array === true;
} catch (e) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions ember_debug/deprecation-debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DebugPort from './debug-port';
import SourceMap from 'ember-debug/libs/source-map';

import { registerDeprecationHandler } from 'ember-debug/utils/ember/debug';
import { debug } from 'ember-debug/utils/ember';
import { guidFor } from 'ember-debug/utils/ember/object/internals';
import { cancel, debounce } from 'ember-debug/utils/ember/runloop';

Expand Down Expand Up @@ -194,7 +194,7 @@ export default class extends DebugPort {
}

handleDeprecations() {
registerDeprecationHandler((message, options, next) => {
debug.registerDeprecationHandler((message, options, next) => {
if (!this.adapter) {
next(message, options);
return;
Expand Down
6 changes: 2 additions & 4 deletions ember_debug/general-debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-empty:0 */
import DebugPort from './debug-port';

import Ember from 'ember-debug/utils/ember';
import { utils } from 'ember-debug/utils/ember';

/**
* Class that handles gathering general information of the inspected app.
Expand Down Expand Up @@ -87,9 +87,7 @@ export default class extends DebugPort {
* the info tab.
*/
getLibraries() {
this.sendMessage('libraries', {
libraries: Ember.libraries?._registry,
});
this.sendMessage('libraries', { libraries: utils.libraries._registry });
},

getEmberCliConfig() {
Expand Down
4 changes: 2 additions & 2 deletions ember_debug/libs/promise-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import Promise from 'ember-debug/models/promise';
import RSVP from 'ember-debug/utils/rsvp';
import { classes } from 'ember-debug/utils/ember';
import BaseObject from 'ember-debug/utils/base-object';
import Evented from 'ember-debug/utils/evented';

Expand All @@ -15,7 +15,7 @@ class PromiseAssembler extends BaseObject {
isStarted = false;

static {
this.prototype.RSVP = RSVP;
this.prototype.RSVP = classes.RSVP;
}

constructor(data) {
Expand Down
16 changes: 8 additions & 8 deletions ember_debug/libs/render-tree.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import captureRenderTree from './capture-render-tree';
import { guidFor } from 'ember-debug/utils/ember/object/internals';
import { EmberLoader, emberSafeRequire } from 'ember-debug/utils/ember/loader';
import { debug, glimmer, ember } from 'ember-debug/utils/ember';
import { inspect } from 'ember-debug/utils/type-check';
import { isInVersionSpecifier } from 'ember-debug/utils/version';
import { VERSION } from 'ember-debug/utils/ember';

class InElementSupportProvider {
constructor(owner) {
this.nodeMap = new Map();
this.remoteRoots = [];
this.runtime = this.require('@glimmer/runtime');
this.runtime = this.require('@glimmer/runtime') || glimmer.runtime;
this.reference = this.require('@glimmer/reference');
try {
this.Wormhole = requireModule('ember-wormhole/components/ember-wormhole');
Expand All @@ -30,7 +29,8 @@ class InElementSupportProvider {
this.registerDestructor =
emberSafeRequire('@glimmer/destroyable')?.registerDestructor ||
emberSafeRequire('@ember/destroyable')?.registerDestructor ||
emberSafeRequire('@ember/runtime')?.registerDestructor;
emberSafeRequire('@ember/runtime')?.registerDestructor ||
glimmer.runtime.registerDestructor;

this.debugRenderTree =
owner.lookup('renderer:-dom')?.debugRenderTree ||
Expand All @@ -52,11 +52,11 @@ class InElementSupportProvider {
const componentStack = [];

const enableModifierSupport =
isInVersionSpecifier('>3.28.0', VERSION) &&
!isInVersionSpecifier('>5.9.0', VERSION);
isInVersionSpecifier('>3.28.0', ember.VERSION) &&
!isInVersionSpecifier('>5.9.0', ember.VERSION);
const hasModifierAndInElementSupport = isInVersionSpecifier(
'>5.9.0',
VERSION
ember.VERSION
);

function createRef(value) {
Expand Down Expand Up @@ -353,7 +353,7 @@ export default class RenderTree {
build() {
this._reset();

this.tree = captureRenderTree(this.owner);
this.tree = debug.captureRenderTree(this.owner);
let serialized = this._serializeRenderNodes(this.tree);

this._releaseStaleObjects();
Expand Down
4 changes: 2 additions & 2 deletions ember_debug/models/profile-manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ProfileNode from './profile-node';
import Ember from 'ember-debug/utils/ember';
import { ember } from 'ember-debug/utils/ember';
import { compareVersion } from 'ember-debug/utils/version';

import { later, scheduleOnce, cancel } from 'ember-debug/utils/ember/runloop';
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class ProfileManager {
this.stylesheet = insertStylesheet();
// keep track of all the active highlights
this.highlights = [];
this.isHighlightEnabled = compareVersion(Ember?.VERSION, '3.20.0') !== -1;
this.isHighlightEnabled = compareVersion(ember?.VERSION, '3.20.0') !== -1;
}

began(timestamp, payload, now) {
Expand Down
78 changes: 31 additions & 47 deletions ember_debug/object-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,27 @@ import {
} from 'ember-debug/utils/type-check';
import { compareVersion } from 'ember-debug/utils/version';
import {
EmberObject,
meta as emberMeta,
VERSION,
CoreObject,
ObjectProxy,
ArrayProxy,
Service,
Component,
classes,
debug,
object,
ember,
glimmer,
} from 'ember-debug/utils/ember';
import { cacheFor, guidFor } from 'ember-debug/utils/ember/object/internals';
import { _backburner, join } from 'ember-debug/utils/ember/runloop';
import emberNames from './utils/ember-object-names';
import getObjectName from './utils/get-object-name';
import { EmberLoader } from 'ember-debug/utils/ember/loader';

const GlimmerComponent = (() => {
try {
return EmberLoader.require('@glimmer/component').default;
} catch (e) {
// ignore, return undefined
}
})();
const { CoreObject, ObjectProxy } = classes;
const { VERSION } = ember;
const { meta: emberMeta } = object;

let tagValue, tagValidate, track, tagForProperty;

try {
// Try to load the most recent library
let GlimmerValidator = EmberLoader.require('@glimmer/validator');
let GlimmerValidator = glimmer.validator;

tagValue = GlimmerValidator.value || GlimmerValidator.valueForTag;
tagValidate = GlimmerValidator.validate || GlimmerValidator.validateTag;
Expand Down Expand Up @@ -83,11 +76,9 @@ try {
}

try {
let metal = EmberLoader.require('@ember/-internals/metal');

tagForProperty = metal.tagForProperty;
tagForProperty = debug.tagForProperty;
// If track was not already loaded, use metal's version (the previous version)
track = track || metal.track;
track = track || debug.track;
} catch (e) {
// ignore
}
Expand Down Expand Up @@ -122,7 +113,7 @@ function inspectValue(object, key, computedValue) {
return { type: `type-${typeOf(value)}`, inspect: inspect(value) };
}

if (value instanceof EmberObject) {
if (value instanceof classes.EmberObject) {
return { type: 'type-ember-object', inspect: value.toString() };
} else if (isComputed(object, key)) {
string = '<computed>';
Expand All @@ -136,18 +127,6 @@ function inspectValue(object, key, computedValue) {
}
}

function isMandatorySetter(descriptor) {
if (
descriptor.set &&
Function.prototype.toString
.call(descriptor.set)
.includes('You attempted to update')
) {
return true;
}
return false;
}

function getTagTrackedTags(tag, ownTag, level = 0) {
const props = [];
// do not include tracked properties from dependencies
Expand Down Expand Up @@ -276,8 +255,7 @@ export default class extends DebugPort {
const tracked = (this.trackedTags[objectId] =
this.trackedTags[objectId] || {});

const desc = Object.getOwnPropertyDescriptor(object, item.name);
const isSetter = desc && isMandatorySetter(desc);
const isSetter = debug.isMandatorySetter(object, item.name);

if (HAS_GLIMMER_TRACKING && item.canTrack && !isSetter) {
let tagInfo = tracked[item.name] || {
Expand Down Expand Up @@ -461,7 +439,7 @@ export default class extends DebugPort {
canSend(val) {
return (
val &&
(val instanceof EmberObject ||
(val instanceof classes.EmberObject ||
val instanceof Object ||
typeOf(val) === 'object' ||
typeOf(val) === 'array')
Expand Down Expand Up @@ -518,7 +496,7 @@ export default class extends DebugPort {
value = value.stack;
}
let args = [value];
if (value instanceof EmberObject) {
if (value instanceof classes.EmberObject) {
args.unshift(inspect(value));
}
this.adapter.log('Ember Inspector ($E): ', ...args);
Expand Down Expand Up @@ -704,7 +682,7 @@ export default class extends DebugPort {
}

if (
object instanceof ArrayProxy &&
object instanceof classes.ArrayProxy &&
object.content &&
!object._showProxyDetails
) {
Expand Down Expand Up @@ -910,7 +888,7 @@ function addProperties(properties, hash) {
continue;
}

let options = { isMandatorySetter: isMandatorySetter(desc) };
let options = { isMandatorySetter: debug.isMandatorySetter(desc) };

if (typeof hash[prop] === 'object' && hash[prop] !== null) {
options.isService =
Expand All @@ -923,7 +901,7 @@ function addProperties(properties, hash) {
}

if (!options.isService) {
options.isService = desc.value instanceof Service;
options.isService = desc.value instanceof classes.Service;
}
}
if (options.isService) {
Expand All @@ -933,9 +911,9 @@ function addProperties(properties, hash) {

if (isComputed(hash, prop)) {
options.isComputed = true;
options.dependentKeys = (desc._dependentKeys || []).map((key) =>
key.toString()
);
options.dependentKeys = (desc._dependentKeys || []).map((key) => ({
name: key.toString(),
}));

if (typeof desc.get === 'function') {
options.code = Function.prototype.toString.call(desc.get);
Expand Down Expand Up @@ -1255,7 +1233,7 @@ function getDebugInfo(object) {
let debugInfo = null;
let objectDebugInfo = object._debugInfo;
if (objectDebugInfo && typeof objectDebugInfo === 'function') {
if (object instanceof ObjectProxy && object.content) {
if (object instanceof classes.ObjectProxy && object.content) {
object = object.content;
}
debugInfo = objectDebugInfo.call(object);
Expand All @@ -1268,7 +1246,7 @@ function getDebugInfo(object) {
skipProperties.push('isDestroyed', 'isDestroying', 'container');
// 'currentState' and 'state' are un-observable private properties.
// The rest are skipped to reduce noise in the inspector.
if (Component && object instanceof Component) {
if (classes.EmberComponent && object instanceof classes.EmberComponent) {
skipProperties.push(
'currentState',
'state',
Expand All @@ -1284,7 +1262,10 @@ function getDebugInfo(object) {
'element',
'targetObject'
);
} else if (GlimmerComponent && object instanceof GlimmerComponent) {
} else if (
classes.GlimmerComponent &&
object instanceof classes.GlimmerComponent
) {
// These properties don't really exist on Glimmer Components, but
// reading their values trigger a development mode assertion. The
// more correct long term fix is to make getters lazy (shows "..."
Expand All @@ -1303,7 +1284,10 @@ function calculateCP(object, item, errorsForObject) {
const property = item.name;
delete errorsForObject[property];
try {
if (object instanceof ArrayProxy && property == parseInt(property)) {
if (
object instanceof classes.ArrayProxy &&
property == parseInt(property)
) {
return object.objectAt(property);
}
return item.isGetter || property.includes?.('.')
Expand Down
4 changes: 2 additions & 2 deletions ember_debug/promise-debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DebugPort from './debug-port';
import PromiseAssembler from 'ember-debug/libs/promise-assembler';
import { debounce } from 'ember-debug/utils/ember/runloop';
import RSVP from 'ember-debug/utils/rsvp';
import { classes } from 'ember-debug/utils/ember';

export default class extends DebugPort {
get objectInspector() {
Expand Down Expand Up @@ -101,7 +101,7 @@ export default class extends DebugPort {
}

setInstrumentWithStack() {
RSVP.configure('instrument-with-stack', this.instrumentWithStack);
classes.RSVP.configure('instrument-with-stack', this.instrumentWithStack);
this.sendInstrumentWithStack();
}

Expand Down
4 changes: 2 additions & 2 deletions ember_debug/render-debug.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import DebugPort from './debug-port';
import ProfileManager from './models/profile-manager';

import { subscribe } from 'ember-debug/utils/ember/instrumentation';
import { _backburner } from 'ember-debug/utils/ember/runloop';
import { instrumentation } from 'ember-debug/utils/ember';
import bound from 'ember-debug/utils/bound-method';

// Initial setup, that has to occur before the EmberObject init for some reason
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class extends DebugPort {
* @private
*/
function _subscribeToRenderEvents() {
subscribe('render', {
instrumentation.subscribe('render', {
before(name, timestamp, payload) {
const info = {
type: 'began',
Expand Down
4 changes: 2 additions & 2 deletions ember_debug/route-debug.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable ember/no-private-routing-service */
import DebugPort from './debug-port';
import { compareVersion } from 'ember-debug/utils/version';
import { VERSION } from 'ember-debug/utils/ember';
import classify from 'ember-debug/utils/classify';
import dasherize from 'ember-debug/utils/dasherize';
import { ember } from 'ember-debug/utils/ember';
import { _backburner, later } from 'ember-debug/utils/ember/runloop';
import bound from 'ember-debug/utils/bound-method';

Expand Down Expand Up @@ -201,7 +201,7 @@ function buildSubTree(routeTree, route) {
// 3.9.0 removed intimate APIs from router
// https://github.com/emberjs/ember.js/pull/17843
// https://deprecations.emberjs.com/v3.x/#toc_remove-handler-infos
if (compareVersion(VERSION, '3.9.0') !== -1) {
if (compareVersion(ember.VERSION, '3.9.0') !== -1) {
// Ember >= 3.9.0
routeHandler = routerLib.getRoute(handler);
} else {
Expand Down
Loading
Loading