Skip to content

Commit

Permalink
refactor: converted forEach loops to for...of
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Nov 1, 2023
1 parent 9702174 commit 71e3a11
Show file tree
Hide file tree
Showing 31 changed files with 639 additions and 938 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Inferno v9 requires following features to be present in the executing runtime:
- `String.prototype.startsWith()`
- `Array.prototype.includes()`
- `Object.spread()`
- `for ... of`

## Browser support
Since version 4 we have started running our test suite **without** any polyfills.
Expand Down
4 changes: 2 additions & 2 deletions docs/animations/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,9 @@ class ShuffleListWithAnimation extends Component {
doClearMarkers = (e) => {
e && e.preventDefault();
const tmp = document.querySelectorAll('.debugMarker');
tmp.forEach((marker) => {
for (const marker of tmp) {
marker.parentNode.removeChild(marker);
});
}
};

componentDidMount() {
Expand Down
4 changes: 2 additions & 2 deletions fixtures/packaging/build-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function buildFixture(tool, environment) {
};
}

fixtureDirs.forEach((dir) => {
for (const dir of fixtureDirs) {
const devPath = path.join(__dirname, dir, 'dev');
if (existsSync(devPath)) {
addResult(dir, 'dev', buildFixture(dir, 'dev'));
Expand All @@ -63,6 +63,6 @@ fixtureDirs.forEach((dir) => {
if (existsSync(prodPath)) {
addResult(dir, 'prod', buildFixture(dir, 'prod'));
}
});
}

console.log(table.toString());
5 changes: 4 additions & 1 deletion packages/inferno-clone-vnode/__tests__/cloneVNode.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,10 @@ the clone</span></div><div name="Henry"><span>A child that should render after t
public render() {
const content: NormalItem[] = [<NormalItem />, <NormalItem />];

items.forEach((_d, idx) => content.push(<Item index={idx} />));
for (const _d of items) {
const idx = items.indexOf(_d);
content.push(<Item index={idx} />);
}

return (
<Wrapper1>
Expand Down
179 changes: 0 additions & 179 deletions packages/inferno-compat/__tests__/ReactChildren.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,185 +120,6 @@ describe('ReactChildren', function () {
expect(React.Children.forEach(null, null, null)).toBe(undefined);
});

// it('should be called for each child', function() {
// var zero = <div key="keyZero" />;
// var one = null;
// var two = <div key="keyTwo" />;
// var three = null;
// var four = <div key="keyFour" />;
//
// var zeroMapped = <div key="giraffe" />; // Key should be joined to obj key
// var oneMapped = null; // Key should be added even if we don't supply it!
// var twoMapped = <div />; // Key should be added even if not supplied!
// var threeMapped = <span />; // Map from null to something.
// var fourMapped = <div key="keyFour" />;
//
// var callback = jasmine.createSpy().and.callFake(function(kid, index) {
// return index === 0 ? zeroMapped :
// index === 1 ? oneMapped :
// index === 2 ? twoMapped :
// index === 3 ? threeMapped : fourMapped;
// });
// var instance = (
// <div>
// {zero}
// {one}
// {two}
// {three}
// {four}
// </div>
// );
//
// ReactChildren.forEach(instance.children, callback);
// expect(callback).toHaveBeenCalledWith(zero, 0);
// expect(callback).toHaveBeenCalledWith(one, 1);
// expect(callback).toHaveBeenCalledWith(two, 2);
// expect(callback).toHaveBeenCalledWith(three, 3);
// expect(callback).toHaveBeenCalledWith(four, 4);
// callback.calls.calls.reset();
//
// var mappedChildren =
// ReactChildren.map(instance.children, callback);
// expect(callback.calls.count()).toBe(5);
// expect(ReactChildren.count(mappedChildren)).toBe(4);
// // Keys default to indices.
// expect([
// mappedChildren[0].key,
// mappedChildren[1].key,
// mappedChildren[2].key,
// mappedChildren[3].key,
// ]).toEqual(
// ['giraffe/.$keyZero', '/.$keyTwo', '/.3', 'keyFour/.$keyFour']
// );
//
// expect(callback).toHaveBeenCalledWith(zero, 0);
// expect(callback).toHaveBeenCalledWith(one, 1);
// expect(callback).toHaveBeenCalledWith(two, 2);
// expect(callback).toHaveBeenCalledWith(three, 3);
// expect(callback).toHaveBeenCalledWith(four, 4);
//
// expect(mappedChildren[0]).toEqual(<div key="giraffe/.$keyZero" />);
// expect(mappedChildren[1]).toEqual(<div key="/.$keyTwo" />);
// expect(mappedChildren[2]).toEqual(<span key="/.3" />);
// expect(mappedChildren[3]).toEqual(<div key="keyFour/.$keyFour" />);
// });

// it('should be called for each child in nested structure', function() {
// var zero = <div key="keyZero" />;
// var one = null;
// var two = <div key="keyTwo" />;
// var three = null;
// var four = <div key="keyFour" />;
// var five = <div key="keyFiveInner" />;
// // five is placed into a JS object with a key that is joined to the
// // component key attribute.
// // Precedence is as follows:
// // 1. If grouped in an Object, the object key combined with `key` prop
// // 2. If grouped in an Array, the `key` prop, falling back to array index

// var zeroMapped = <div key="giraffe" />; // Key should be overridden
// var twoMapped = <div />; // Key should be added even if not supplied!
// var fourMapped = <div key="keyFour" />;
// var fiveMapped = <div />;

// var callback = jasmine.createSpy().and.callFake(function(kid, index) {
// return index === 0 ? zeroMapped :
// index === 1 ? twoMapped :
// index === 2 ? fourMapped : fiveMapped;
// });

// var frag = ReactFragment.create({
// firstHalfKey: [zero, one, two],
// secondHalfKey: [three, four],
// keyFive: five,
// });
// var instance = <div>{[frag]}</div>;

// expect([
// frag[0].key,
// frag[1].key,
// frag[2].key,
// frag[3].key,
// ]).toEqual([
// 'firstHalfKey/.$keyZero',
// 'firstHalfKey/.$keyTwo',
// 'secondHalfKey/.$keyFour',
// 'keyFive/.$keyFiveInner',
// ]);

// ReactChildren.forEach(instance.props.children, callback);
// expect(callback.calls.count()).toBe(4);
// expect(callback).toHaveBeenCalledWith(frag[0], 0);
// expect(callback).toHaveBeenCalledWith(frag[1], 1);
// expect(callback).toHaveBeenCalledWith(frag[2], 2);
// expect(callback).toHaveBeenCalledWith(frag[3], 3);
// callback.calls.calls.reset();

// var mappedChildren = ReactChildren.map(instance.props.children, callback);
// expect(callback.calls.count()).toBe(4);
// expect(callback).toHaveBeenCalledWith(frag[0], 0);
// expect(callback).toHaveBeenCalledWith(frag[1], 1);
// expect(callback).toHaveBeenCalledWith(frag[2], 2);
// expect(callback).toHaveBeenCalledWith(frag[3], 3);

// expect(ReactChildren.count(mappedChildren)).toBe(4);
// // Keys default to indices.
// expect([
// mappedChildren[0].key,
// mappedChildren[1].key,
// mappedChildren[2].key,
// mappedChildren[3].key,
// ]).toEqual([
// 'giraffe/.0:$firstHalfKey/=1$keyZero',
// '/.0:$firstHalfKey/=1$keyTwo',
// 'keyFour/.0:$secondHalfKey/=1$keyFour',
// '/.0:$keyFive/=1$keyFiveInner',
// ]);

// expect(mappedChildren[0]).toEqual(<div key="giraffe/.0:$firstHalfKey/=1$keyZero" />);
// expect(mappedChildren[1]).toEqual(<div key="/.0:$firstHalfKey/=1$keyTwo" />);
// expect(mappedChildren[2]).toEqual(<div key="keyFour/.0:$secondHalfKey/=1$keyFour" />);
// expect(mappedChildren[3]).toEqual(<div key="/.0:$keyFive/=1$keyFiveInner" />);
// });

// it('should retain key across two mappings', function() {
// var zeroForceKey = <div key="keyZero" />;
// var oneForceKey = <div key="keyOne" />;
//
// // Key should be joined to object key
// var zeroForceKeyMapped = <div key="giraffe" />;
// // Key should be added even if we don't supply it!
// var oneForceKeyMapped = <div />;
//
// var mapFn = function(kid, index) {
// return index === 0 ? zeroForceKeyMapped : oneForceKeyMapped;
// };
//
// var forcedKeys = (
// <div>
// {zeroForceKey}
// {oneForceKey}
// </div>
// );
//
// var expectedForcedKeys = ['giraffe/.$keyZero', '/.$keyOne'];
// var mappedChildrenForcedKeys =
// ReactChildren.map(forcedKeys.props.children, mapFn);
// var mappedForcedKeys = mappedChildrenForcedKeys.map((c) => c.key);
// expect(mappedForcedKeys).toEqual(expectedForcedKeys);
//
// // var expectedRemappedForcedKeys = [
// // 'giraffe/.$giraffe/=1$keyZero',
// // '/.$/=1$keyOne',
// // ];
// // var remappedChildrenForcedKeys =
// // ReactChildren.map(mappedChildrenForcedKeys, mapFn);
// // expect(
// // remappedChildrenForcedKeys.map((c) => c.key)
// // ).toEqual(expectedRemappedForcedKeys);
//
// });

it('should not throw if key provided is a dupe with array key', function () {
const zero = <div />;
const one = <div key="0" />;
Expand Down
15 changes: 0 additions & 15 deletions packages/inferno-compat/__tests__/ReactES6Class.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,6 @@ describe('ReactES6Class', function () {
expect(renderCount).toBe(1);
});

// it('should throw with non-object in the initial state property', function() {
// [['an array'], 'a string', 1234].forEach(function(state) {
// class Foo extends React.Component {
// constructor() {
// super();
// this.state = state;
// }
// render() {
// return <span />;
// }
// }
// expect(() => test(<Foo />, 'span', '')).toThrow();
// });
// });

it('should render with null in the initial state property', function () {
class Foo extends React.Component {
constructor() {
Expand Down
4 changes: 2 additions & 2 deletions packages/inferno-compat/src/InfernoCompatPropertyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function capitalize(token: string): string {
return token[1].toUpperCase();
}

ATTRS.forEach((original) => {
for (const original of ATTRS) {
const reactName = original.replace(CAMELIZE, capitalize);

InfernoCompatPropertyMap[reactName] = original;
});
}
Loading

0 comments on commit 71e3a11

Please sign in to comment.