Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
guyca committed Jan 6, 2025
1 parent c55fb36 commit 429b03d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions packages/react-obsidian/src/graph/registry/GraphRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,25 @@ export class GraphRegistry {
subgraph => getMetadata(subgraph, 'lifecycleScope') === customScope,
);
const instantiatedSubgraphs = sameScopeSubgraphs.map(
subgraph => {
(subgraph) => {
return this.resolve(subgraph, 'lifecycleOwner', props);
},
);
instantiatedSubgraphs.forEach((subgraph) => referenceCounter.retain(subgraph));
instantiatedSubgraphs.forEach(subgraph => referenceCounter.retain(subgraph));
this.registerOnClearListener(graph, () => {
instantiatedSubgraphs.forEach((subgraph) => referenceCounter.release(subgraph, () => this.clear(subgraph)));
instantiatedSubgraphs.forEach(subgraph => referenceCounter.release(subgraph, () => this.clear(subgraph)));
});
}

private assertInstantiatingCustomScopedSubgraphFromSameScope(graph: Graph) {
const graphScope = getMetadata(this.instanceToConstructor.get(graph)!, 'lifecycleScope');
const subgraphs = this.getSubgraphsConstructors(graph);
subgraphs.forEach(subgraph => {
subgraphs.forEach((subgraph) => {
const subgraphScope = getMetadata(subgraph, 'lifecycleScope');
if (
!this.isInstantiated(subgraph) &&
this.isCustomScopedLifecycleBound(subgraph) &&
graphScope !== subgraphScope
!this.isInstantiated(subgraph)
&& this.isCustomScopedLifecycleBound(subgraph)
&& graphScope !== subgraphScope
) {
throw new Error(`Cannot instantiate the scoped graph '${subgraph.name}' as a subgraph of '${graph.constructor.name}' because the scopes do not match. ${graphScope} !== ${subgraphScope}`);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ export class GraphRegistry {
private invokeOnClearListeners(graph: Graph) {
const listeners = this.onClearListeners.get(graph);
if (!listeners) return;
listeners.forEach((listener) => listener());
listeners.forEach(listener => listener());
this.onClearListeners.delete(graph);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ObjectGraph,
Singleton,
} from '../../src';
import graphRegistry from '../../src/graph/registry/GraphRegistry';
import graphRegistry from '../../src/graph/registry/GraphRegistry';

describe('custom scoped lifecycle-bound graphs', () => {
it('instantiates custom scoped graphs eagerly', () => {
Expand All @@ -21,8 +21,8 @@ describe('custom scoped lifecycle-bound graphs', () => {
expect(CustomScopeGraph.idx).toBe(1);
});

it('clears the custom scoped subgraph when the main graph is cleared', async () => {
const {unmount} = render(<ComponentTheDoesNotInvokeProviders idx={1} />);
it('clears the custom scoped subgraph when the main graph is cleared', () => {
const { unmount } = render(<ComponentTheDoesNotInvokeProviders idx={1} />);
unmount();
expect(graphRegistry.isInstantiated(CustomScopeGraph)).toBe(false);
});
Expand All @@ -37,7 +37,7 @@ describe('custom scoped lifecycle-bound graphs', () => {
expect(graphRegistry.isInstantiated(CustomScopeGraph)).toBe(false);
});

it('throws when trying to use a scoped subgraph from an unscoped graph', async () => {
it('throws when trying to use a scoped subgraph from an unscoped graph', () => {
expect(() => {
render(<ComponentThatWronglyReliesOnCustomScopedGraph />);
}).toThrow(/Cannot instantiate the scoped graph 'CustomScopeGraph' as a subgraph of 'UnscopedGraph' because the scopes do not match. undefined !== customScope/);
Expand All @@ -49,7 +49,7 @@ describe('custom scoped lifecycle-bound graphs', () => {
});
});

@LifecycleBound({scope: 'customScope'}) @Graph()
@LifecycleBound({ scope: 'customScope' }) @Graph()
class CustomScopeGraph extends ObjectGraph {
public static idx: number;

Expand All @@ -59,17 +59,17 @@ class CustomScopeGraph extends ObjectGraph {
}
}

@LifecycleBound({scope: 'customScope'}) @Graph({subgraphs: [CustomScopeGraph]})
@LifecycleBound({ scope: 'customScope' }) @Graph({ subgraphs: [CustomScopeGraph] })
class ComponentGraph extends ObjectGraph {
}

@LifecycleBound({scope: 'customScope'}) @Graph({subgraphs: [CustomScopeGraph]})
@LifecycleBound({ scope: 'customScope' }) @Graph({ subgraphs: [CustomScopeGraph] })
class ComponentGraph2 extends ObjectGraph {
}

type Own = {idx: number};
type Own = { idx: number };
const ComponentTheDoesNotInvokeProviders = injectComponent<Own>(
({idx}: Own) => <>Hello {idx}</>,
({ idx }: Own) => <>Hello {idx}</>,
ComponentGraph,
);

Expand All @@ -78,7 +78,7 @@ const ComponentTheDoesNotInvokeProviders2 = injectComponent(
ComponentGraph2,
);

@Graph({subgraphs: [CustomScopeGraph]})
@Graph({ subgraphs: [CustomScopeGraph] })
class UnscopedGraph extends ObjectGraph {
}

Expand All @@ -87,11 +87,11 @@ const ComponentThatWronglyReliesOnCustomScopedGraph = injectComponent(
UnscopedGraph,
);

@Singleton() @Graph({subgraphs: [CustomScopeGraph]})
@Singleton() @Graph({ subgraphs: [CustomScopeGraph] })
class SingletonGraphWithCustomScopeSubgraph extends ObjectGraph {
}

@LifecycleBound({scope: 'customScope'}) @Graph({subgraphs: [SingletonGraphWithCustomScopeSubgraph]})
@LifecycleBound({ scope: 'customScope' }) @Graph({ subgraphs: [SingletonGraphWithCustomScopeSubgraph] })
class CustomScopedGraphWithNestedCustomScopeSubgraph extends ObjectGraph {
}

Expand Down

0 comments on commit 429b03d

Please sign in to comment.