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 28, 2023
1 parent 7c86dbd commit e403516
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 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, infoForTag, tagFor, type TagMeta, tagMetaFor } from './lib/meta';
export { trackedData } from './lib/tracked-data';
export {
beginTrackFrame,
Expand Down
16 changes: 16 additions & 0 deletions packages/@glimmer/validator/lib/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ 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<
UpdatableTag|ConstantTag,
{
object: Object;
propertyKey: string | number | symbol;
}
>();

export function dirtyTagFor<T extends object>(
obj: T,
Expand Down Expand Up @@ -67,5 +74,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: UpdatableTag|ConstantTag) {
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, infoForTag, tagFor, validateTag, valueForTag } 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);
assert.strictEqual(info.propertyKey, 'foo');
});
});

0 comments on commit e403516

Please sign in to comment.