Skip to content

Commit

Permalink
provide debug utlities for inspector via event communication
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Nov 28, 2023
1 parent e5e561f commit c7e2bab
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/@ember/-internals/metal/lib/cached.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { DEBUG } from '@glimmer/env';
import { createCache, getValue } from '@glimmer/validator';

const CacheMap = new WeakMap();

/**
* @decorator
*
Expand Down Expand Up @@ -84,7 +86,7 @@ import { createCache, getValue } from '@glimmer/validator';
the subsequent cache invalidations of the `@cached` properties who were
using this `trackedProp`.
Remember that setting tracked data should only be done during initialization,
Remember that setting tracked data should only be done during initialization,
or as the result of a user action. Setting tracked data during render
(such as in a getter), is not supported.
Expand All @@ -111,6 +113,8 @@ export const cached: PropertyDecorator = (...args: any[]) => {
throwCachedGetterOnlyError(key);
}

CacheMap.set(target, [...CacheMap.get(target)||[], key]);

Check failure on line 116 in packages/@ember/-internals/metal/lib/cached.ts

View workflow job for this annotation

GitHub Actions / Linting

Replace `CacheMap.get(target)||[]` with `(CacheMap.get(target)·||·[])`

const caches = new WeakMap();
const getter = descriptor.get;

Expand Down Expand Up @@ -144,3 +148,8 @@ function throwCachedInvalidArgsError(args: unknown[] = []): never {
)}), which is not supported. Dependencies are automatically tracked, so you can just use ${'`@cached`'}`
);
}

Check failure on line 150 in packages/@ember/-internals/metal/lib/cached.ts

View workflow job for this annotation

GitHub Actions / Linting

Delete `⏎`


export function isCachedProperty(object: object, prop: string) {
return (CacheMap.get(object) || []).includes(prop);
}
5 changes: 5 additions & 0 deletions packages/@ember/-internals/metal/lib/tracked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,8 @@ export class TrackedDescriptor {
this._set.call(obj, value);
}
}


Check failure on line 204 in packages/@ember/-internals/metal/lib/tracked.ts

View workflow job for this annotation

GitHub Actions / Linting

Delete `⏎`
export function isTrackedProperty(object: object, prop: string): boolean {
return metaFor(object).peekDescriptors(prop) instanceof TrackedDescriptor;
}
1 change: 1 addition & 0 deletions packages/@ember/-internals/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export {
setupMandatorySetter,
teardownMandatorySetter,
setWithMandatorySetter,
isMandatorySetter

Check failure on line 35 in packages/@ember/-internals/utils/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Insert `,`
} from './lib/mandatory-setter';
8 changes: 8 additions & 0 deletions packages/@ember/-internals/utils/lib/mandatory-setter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export let setupMandatorySetter:
export let teardownMandatorySetter: ((obj: object, keyName: string | symbol) => void) | undefined;
export let setWithMandatorySetter: ((obj: object, keyName: string, value: any) => void) | undefined;

export let isMandatorySetter: ((obj: object, keyName: string) => boolean) | undefined;

type PropertyDescriptorWithMeta = PropertyDescriptor & { hadOwnProperty?: boolean };

function isElementKey(key: string | number | symbol) {
Expand All @@ -25,6 +27,7 @@ function isPositiveInt(num: number) {
return num >= 0 && num % 1 === 0;
}

Check failure on line 29 in packages/@ember/-internals/utils/lib/mandatory-setter.ts

View workflow job for this annotation

GitHub Actions / Linting

Delete `⏎`

if (DEBUG) {
let SEEN_TAGS = new WeakSet();

Expand Down Expand Up @@ -94,6 +97,11 @@ if (DEBUG) {
});
};

isMandatorySetter = function (obj: object, keyName: string) {
let setters = MANDATORY_SETTERS.get(obj);
return setters !== undefined && setters[keyName] !== undefined;

Check failure on line 102 in packages/@ember/-internals/utils/lib/mandatory-setter.ts

View workflow job for this annotation

GitHub Actions / Linting

Insert `;`
}

teardownMandatorySetter = function (obj: object, keyName: string | symbol) {
let setters = MANDATORY_SETTERS.get(obj);

Expand Down
113 changes: 113 additions & 0 deletions packages/@ember/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,47 @@ export { default as inspect } from './lib/inspect';
export { isTesting, setTesting } from './lib/testing';
export { default as captureRenderTree } from './lib/capture-render-tree';

// required for inspector
import { _backburner, cancel, debounce, join, later, scheduleOnce } from '@ember/runloop';
import { cacheFor, guidFor } from '@ember/object/internals';
import { default as MutableArray } from '@ember/array/mutable';
import { default as Namespace } from '@ember/application/namespace';
import { default as MutableEnumerable } from'@ember/enumerable/mutable';

Check failure on line 21 in packages/@ember/debug/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Insert `·`
import { NativeArray } from '@ember/array';
import { ControllerMixin } from '@ember/controller';
import { default as CoreObject } from '@ember/object/core';
import { default as Application } from '@ember/application';
import { default as EmberComponent } from '@ember/component';
import { default as Observable } from '@ember/object/observable';
import { default as Evented } from '@ember/object/evented';
import { default as PromiseProxyMixin } from '@ember/object/promise-proxy-mixin';
import { default as EmberObject } from '@ember/object';
import { default as VERSION } from 'ember/version';
import { ComputedProperty, isComputed, descriptorForProperty, descriptorForDecorator, tagForProperty } from '@ember/-internals/metal';

Check failure on line 32 in packages/@ember/debug/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Replace `·ComputedProperty,·isComputed,·descriptorForProperty,·descriptorForDecorator,·tagForProperty·` with `⏎··ComputedProperty,⏎··isComputed,⏎··descriptorForProperty,⏎··descriptorForDecorator,⏎··tagForProperty,⏎`
import { isMandatorySetter } from '@ember/-internals/utils'

Check failure on line 33 in packages/@ember/debug/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Insert `;`
import { meta } from '@ember/-internals/meta';
import { TargetActionSupport } from '@ember/-internals/runtime';
import {
ViewStateSupport,
ViewMixin,
ActionSupport,
ClassNamesSupport,
ChildViewsSupport,
CoreView

Check failure on line 42 in packages/@ember/debug/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Insert `,`
} from '@ember/-internals/views';
import { set, get } from '@ember/object';
import { isTrackedProperty } from '@ember/-internals/metal/lib/tracked';
import { isCachedProperty } from '@ember/-internals/metal/lib/cached';
import { default as inspect } from './lib/inspect';
import { subscribe } from '../instrumentation';
import { default as captureRenderTree } from './lib/capture-render-tree';
import { registerHandler as registerDeprecationHandler } from './lib/deprecate';
import * as GlimmerValidator from '@glimmer/validator';
import * as GlimmerRuntime from '@glimmer/runtime';
import { getOwner } from '@glimmer/owner';
import RSVP from 'rsvp';


export type DebugFunctionType =
| 'assert'
| 'info'
Expand Down Expand Up @@ -342,6 +383,78 @@ if (DEBUG && !isTesting()) {
},
false
);
window.addEventListener(
'ember-inspector-debug-request',
() => {
const event = new CustomEvent("ember-inspector-debug-response", { detail: {
runloop: {
_backburner,
cancel,
debounce,
join,
later,
scheduleOnce,
},
object: {
cacheFor,
guidFor,
getOwner,
set,
get,
meta
},
debug: {
isComputed,
isTrackedProperty,
isCachedProperty,
descriptorForProperty,
descriptorForDecorator,
isMandatorySetter,
meta,
captureRenderTree,
isTesting,
inspect,
registerDeprecationHandler,
tagForProperty,
ComputedProperty,
infoForTag: GlimmerValidator.infoForTag

Check failure on line 420 in packages/@ember/debug/index.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Property 'infoForTag' does not exist on type 'typeof import("/home/runner/work/ember.js/ember.js/node_modules/.pnpm/@Glimmer[email protected]/node_modules/@glimmer/validator/dist/dev/index")'.

Check failure on line 420 in packages/@ember/debug/index.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Property 'infoForTag' does not exist on type 'typeof import("/home/runner/work/ember.js/ember.js/node_modules/.pnpm/@Glimmer[email protected]/node_modules/@glimmer/validator/dist/dev/index")'.
},
classes: {
EmberObject,
MutableArray,
Namespace,
MutableEnumerable,
NativeArray,
TargetActionSupport,
ControllerMixin,
CoreObject,
Application,
EmberComponent,
Observable,
Evented,
PromiseProxyMixin,
},
VERSION,
instrumentation: {
subscribe
},
Views: {
ViewStateSupport,
ViewMixin,
ActionSupport,
ClassNamesSupport,
ChildViewsSupport,
CoreView
},
GlimmerValidator,
GlimmerRuntime,
RSVP
}
});
window.dispatchEvent(event);
},
false
);
}
}

Expand Down

0 comments on commit c7e2bab

Please sign in to comment.