Skip to content

Commit 2c2adf7

Browse files
Fix provider global clenup on error (#89)
1 parent 59fec0a commit 2c2adf7

File tree

12 files changed

+97
-48
lines changed

12 files changed

+97
-48
lines changed

examples/.babelrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
module.exports = {
44
extends: '../babel.config.js',
55
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow'],
6-
plugins: ['@babel/plugin-proposal-class-properties', '../src/babel'],
6+
plugins: [
7+
'@babel/plugin-proposal-class-properties',
8+
['../src/babel', { enabledEnvs: ['development', 'test', undefined] }],
9+
],
710
};

examples/flow/components/input.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22
import React, { useState, type Node } from 'react';
3-
import { di } from 'react-magnetic-di';
43

54
type UseThemeState = { color: string };
65
export function useTheme(): $Call<typeof useState, UseThemeState> {
@@ -12,7 +11,6 @@ export type InputProps = {|
1211
|};
1312

1413
export function Input(props: InputProps): Node {
15-
di(useTheme);
1614
const [style] = useTheme();
1715

1816
return (

examples/flow/components/label.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22
import React, { useState, type Node } from 'react';
3-
import { di } from 'react-magnetic-di';
43

54
type UseThemeState = { color: string };
65
export function useTheme(): $Call<typeof useState, UseThemeState> {
@@ -12,7 +11,6 @@ type LabelProps = {|
1211
|};
1312

1413
export function Label({ children = 'Label' }: LabelProps): Node {
15-
di(useTheme);
1614
const [style] = useTheme();
1715
return <div style={style}>{children}</div>;
1816
}

examples/flow/components/section.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22
import React, { Component, type Node } from 'react';
3-
import { di } from 'react-magnetic-di';
43

54
import { Label } from './label';
65
import { Input } from './input';
@@ -11,8 +10,6 @@ type Props = {|
1110

1211
export class Section extends Component<Props> {
1312
render(): Node {
14-
di(Input, Label);
15-
1613
const { title } = this.props;
1714
return (
1815
<div>

examples/global/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import { di } from 'react-magnetic-di';
2-
31
type Data = { data: number[] };
42

53
export const fetchApi = async (): Promise<Data> => ({ data: [1, 2] });
64
export const processApiData = (data: Data['data']) => data.map((v) => v * v);
75

86
export function transformer(response: Data) {
9-
di(processApiData);
107
return processApiData(response.data);
118
}
129

1310
export async function apiHandler() {
14-
di(fetchApi, transformer);
1511
const data = await fetchApi();
1612
return transformer(data);
1713
}

examples/typescript/components/input.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22
import React, { useState } from 'react';
3-
import { di } from 'react-magnetic-di';
43

54
type UseThemeState = { color: string };
65
export function useTheme() {
@@ -12,7 +11,6 @@ export type InputProps = {
1211
};
1312

1413
export function Input(props: InputProps) {
15-
di(useTheme);
1614
const [style] = useTheme();
1715

1816
return (

examples/typescript/components/label.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// @flow
21
import React, { type ReactNode, useState } from 'react';
3-
import { di } from 'react-magnetic-di';
42

53
type UseThemeState = { color: string };
64
export function useTheme() {
@@ -12,7 +10,6 @@ type LabelProps = {
1210
};
1311

1412
export function Label({ children = 'Label' }: LabelProps) {
15-
di(useTheme);
1613
const [style] = useTheme();
1714
return <div style={style}>{children}</div>;
1815
}

examples/typescript/components/section.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// @flow
21
import React, { Component } from 'react';
3-
import { di } from 'react-magnetic-di';
42

53
import { Label } from './label';
64
import { Input } from './input';
@@ -11,8 +9,6 @@ type Props = {
119

1210
export class Section extends Component<Props> {
1311
render() {
14-
di(Input, Label);
15-
1612
const { title } = this.props;
1713
return (
1814
<div>

src/eslint/rules/no-extraneous.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ module.exports = {
6262

6363
blockReferences.set(node, {
6464
di: diVars,
65-
through: context.getScope().through.map((v) => v.identifier),
65+
through: context.sourceCode
66+
.getScope(node)
67+
.through.map((v) => v.identifier),
6668
});
6769
},
6870

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { di } from './react/consumer';
2-
export { runWithDi } from './react/global';
2+
export { runWithDi, globalDi as unstable_globalDi } from './react/global';
33
export { DiProvider, withDi } from './react/provider';
44
export { injectable } from './react/injectable';
55
export { debug } from './react/utils';

0 commit comments

Comments
 (0)