Skip to content

Commit

Permalink
add tag info for ember-inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Nov 3, 2023
1 parent e993f37 commit 25ec20f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@glimmer/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (globalObj[GLIMMER_VALIDATOR_REGISTRATION] === true) {
globalObj[GLIMMER_VALIDATOR_REGISTRATION] = true;

export { debug } from './lib/debug';
export { dirtyTagFor, tagFor, type TagMeta, tagMetaFor } from './lib/meta';
export { dirtyTagFor, tagFor, type TagMeta, tagMetaFor, infoForTag } from './lib/meta';
export { trackedData } from './lib/tracked-data';
export {
beginTrackFrame,
Expand Down
12 changes: 11 additions & 1 deletion packages/@glimmer/validator/lib/meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ConstantTag, UpdatableTag } from "@glimmer/interfaces";
import type { ConstantTag, Tag, UpdatableTag } from '@glimmer/interfaces';

import { debug } from './debug';
import { type Indexable, unwrap } from './utils';
Expand All @@ -13,6 +13,7 @@ function isObjectLike<T>(u: T): u is Indexable & T {
export type TagMeta = Map<PropertyKey, UpdatableTag>;

const TRACKED_TAGS = new WeakMap<object, TagMeta>();
const TAG_INFO = new WeakMap<Tag, Record<string, any>>

export function dirtyTagFor<T extends object>(
obj: T,
Expand Down Expand Up @@ -65,5 +66,14 @@ export function tagFor<T extends object>(
tags.set(key, tag);
}

TAG_INFO.set(tag, {
propertyKey: key,
object: obj
});

return tag;
}

export function infoForTag(tag: Tag) {
return TAG_INFO.get(tag)
}
11 changes: 10 additions & 1 deletion packages/@glimmer/validator/test/meta-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirtyTagFor, tagFor, validateTag, valueForTag } from '@glimmer/validator';
import { dirtyTagFor, tagFor, validateTag, valueForTag, infoForTag } from '@glimmer/validator';

import { module, test } from './-utils';

Expand All @@ -18,4 +18,13 @@ module('@glimmer/validator: meta', () => {

assert.notOk(validateTag(tag, snapshot));
});

test('it can provide the object and property for the tag given object', (assert) => {
let obj = {};
let tag = tagFor(obj, 'foo');

let info = infoForTag(tag)!;
assert.strictEqual(info.object, obj);

Check failure on line 27 in packages/@glimmer/validator/test/meta-test.ts

View workflow job for this annotation

GitHub Actions / Linting

Property 'object' comes from an index signature, so it must be accessed with ['object'].
assert.strictEqual(info.propertyKey, 'foo');

Check failure on line 28 in packages/@glimmer/validator/test/meta-test.ts

View workflow job for this annotation

GitHub Actions / Linting

Property 'propertyKey' comes from an index signature, so it must be accessed with ['propertyKey'].
});
});

0 comments on commit 25ec20f

Please sign in to comment.