Skip to content

Commit

Permalink
Merge pull request #1088 from glimmerjs/interal/rename-memoize-tracked
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored May 11, 2020
2 parents a0d1eec + c0cd3fa commit 140af2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/@glimmer/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export {
isTracking,
track,
trackedData,
memoizeTracked,
memo,
untrack,
isConstMemo,
} from './lib/tracking';
Expand Down
17 changes: 7 additions & 10 deletions packages/@glimmer/validator/lib/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,26 @@ export function endTrackFrame(): Tag {

const IS_CONST_MAP: WeakMap<object, boolean | undefined> = new WeakMap();

export function memoizeTracked<T>(cb: () => T, context?: string | false): () => T;
export function memoizeTracked<T, U>(cb: (a1: U) => T, context?: string | false): (a1: U) => T;
export function memoizeTracked<T, U, V, W>(
export function memo<T>(cb: () => T, context?: string | false): () => T;
export function memo<T, U>(cb: (a1: U) => T, context?: string | false): (a1: U) => T;
export function memo<T, U, V, W>(
cb: (a1: U, a2: V, a3: W) => T,
context?: string | false
): (a1: U, a2: V, a3: W) => T;
export function memoizeTracked<T, U, V, W, X>(
export function memo<T, U, V, W, X>(
cb: (a1: U, a2: V, a3: W, a4: X) => T,
context?: string | false
): (a1: U, a2: V, a3: W, a4: X) => T;
export function memoizeTracked<T, U, V, W, X, Y>(
export function memo<T, U, V, W, X, Y>(
cb: (a1: U, a2: V, a3: W, a4: X, a5: Y) => T,
context?: string | false
): (a1: U, a2: V, a3: W, a4: X, a5: Y) => T;
export function memoizeTracked<T, U, V, W, X, Y, Z>(
export function memo<T, U, V, W, X, Y, Z>(
cb: (a1: U, a2: V, a3: W, a4: X, a5: Y, a6: Z) => T,
context?: string | false
): (a1: U, a2: V, a3: W, a4: X, a5: Y, a6: Z) => T;

export function memoizeTracked<T>(
callback: (...args: unknown[]) => T,
debuggingContext?: string | false
) {
export function memo<T>(callback: (...args: unknown[]) => T, debuggingContext?: string | false) {
let lastValue: T | undefined;
let tag: Tag;
let snapshot: Revision;
Expand Down
20 changes: 10 additions & 10 deletions packages/@glimmer/validator/test/tracking-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
setPropertyDidChange,
tagFor,
track,
memoizeTracked,
memo,
trackedData,
untrack,
validateTag,
Expand Down Expand Up @@ -263,13 +263,13 @@ module('@glimmer/validator: tracking', () => {
});
});

module('memoizeTracked', () => {
module('memo', () => {
test('it memoizes based on tags that are consumed within a track frame', assert => {
let tag1 = createTag();
let tag2 = createTag();
let count = 0;

let fn = memoizeTracked(() => {
let fn = memo(() => {
consumeTag(tag1);
consumeTag(tag2);

Expand All @@ -293,7 +293,7 @@ module('@glimmer/validator: tracking', () => {
let tag2 = createTag();
let count = 0;

let fn = memoizeTracked(() => {
let fn = memo(() => {
consumeTag(tag1);

untrack(() => consumeTag(tag2));
Expand All @@ -319,13 +319,13 @@ module('@glimmer/validator: tracking', () => {
let innerCount = 0;
let outerCount = 0;

let innerFn = memoizeTracked(() => {
let innerFn = memo(() => {
consumeTag(innerTag);

return ++innerCount;
});

let outerFn = memoizeTracked(() => {
let outerFn = memo(() => {
consumeTag(outerTag);

return [++outerCount, innerFn()];
Expand All @@ -349,7 +349,7 @@ module('@glimmer/validator: tracking', () => {
assert.expect(3);
assert.notOk(isTracking());

let fn = memoizeTracked(() => {
let fn = memo(() => {
assert.ok(isTracking());

untrack(() => {
Expand All @@ -363,11 +363,11 @@ module('@glimmer/validator: tracking', () => {
test('isConstMemo allows users to check if a memoized function is constant', assert => {
let tag = createTag();

let constFn = memoizeTracked(() => {
let constFn = memo(() => {
// do nothing;
});

let nonConstFn = memoizeTracked(() => {
let nonConstFn = memo(() => {
consumeTag(tag);
});

Expand All @@ -380,7 +380,7 @@ module('@glimmer/validator: tracking', () => {

if (DEBUG) {
test('isConstMemo throws an error in DEBUG mode if users attempt to check a function before it has been called', assert => {
let fn = memoizeTracked(() => {
let fn = memo(() => {
// do nothing;
});

Expand Down

0 comments on commit 140af2a

Please sign in to comment.