Skip to content

Commit

Permalink
Remove missing stats API (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogasparin authored May 30, 2023
1 parent 7f51721 commit 03ed319
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 50 deletions.
2 changes: 0 additions & 2 deletions src/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ declare export function runWithDi<T: (...args: any) => any>(
declare export var stats: {
/** Returns unused injectables */
unused: () => Array<{ get: () => Dependency, error: () => Error }>,
/** Returns dependencies missing an injectable override */
missing: () => Array<{ get: () => Dependency, error: () => Error }>,
/** Resets stats */
reset: () => void,
};
Expand Down
20 changes: 0 additions & 20 deletions src/react/__tests__/stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
WrapperDi,
apiHandler,
fetchApiDi,
processApiData,
processApiDataDi,
transformer,
} from './common';

describe('stats', () => {
Expand Down Expand Up @@ -65,16 +63,6 @@ describe('stats', () => {
);
expect(stats.unused()).toHaveLength(0);
});

it('should track missing injectables', () => {
render(
<DiProvider use={[TextDi]}>
<Label />
</DiProvider>
);
expect(stats.missing()).toHaveLength(1);
expect(stats.missing()[0].get()).toEqual(Wrapper);
});
});

describe('with runWithDi', () => {
Expand All @@ -91,13 +79,5 @@ describe('stats', () => {
expect(stats.unused()[0].get()).toEqual(TextDi);
expect(stats.unused()[1].get()).toEqual(WrapperDi);
});

it('should track missing injectables', async () => {
const deps = [fetchApiDi];
await runWithDi(() => apiHandler(), deps);
expect(stats.missing()).toHaveLength(2);
expect(stats.missing()[0].get()).toEqual(transformer);
expect(stats.missing()[1].get()).toEqual(processApiData);
});
});
});
5 changes: 0 additions & 5 deletions src/react/__tests__/types.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,9 @@ async () => {
* stats types tests
*/
const unused = stats.unused();
const missing = stats.missing();
stats.reset();

// Correct
unused.length > 1;
unused[0].get().call;
unused[0].error().stack;

missing.length > 1;
missing[0].get().call;
missing[0].error().stack;
16 changes: 0 additions & 16 deletions src/react/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { KEY } from './constants';
const createState = () => ({
unused: new Map(),
used: new Set(),
missing: new Map(),
provided: new Set(),
});

Expand All @@ -29,13 +28,7 @@ export const stats = {
if (replacedDep) {
this.state.unused.delete(replacedDep);
this.state.used.add(replacedDep);
this.state.missing.delete(dep);
this.state.provided.add(dep);
} else if (!dep[KEY]?.from && !this.state.provided.has(dep)) {
this.state.missing.set(
dep,
new Error(`Unreplaced di dependency: ${dep.displayName || dep}`)
);
}
},

Expand All @@ -51,13 +44,4 @@ export const stats = {
})
);
},

missing() {
return Array.from(this.state.missing.entries()).map(
([dependency, error]) => ({
get: () => dependency,
error: () => error,
})
);
},
};
2 changes: 0 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ declare module 'react-magnetic-di' {
const stats: {
/** Returns unused injectables */
unused(): Array<{ get(): Injectable; error(): Error }>;
/** Returns dependencies missing an injectable override */
missing(): Array<{ get(): Dependency; error(): Error }>;
/** Resets stats */
reset(): void;
};
Expand Down
5 changes: 0 additions & 5 deletions types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,9 @@ async () => {
* stats types tests
*/
const unused = stats.unused();
const missing = stats.missing();
stats.reset();

// Correct
unused.length > 1;
unused[0].get().call;
unused[0].error().stack;

missing.length > 1;
missing[0].get().call;
missing[0].error().stack;

0 comments on commit 03ed319

Please sign in to comment.