Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit e8b01e2

Browse files
committed
swapped date.now for performance.now
this was listed as a nice to have in lighthouse for PWA, since it decouples from system clock and is more consistent
1 parent 25cf0b7 commit e8b01e2

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/components/world.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React, { Component, PropTypes } from 'react';
1+
import React, {Component, PropTypes} from 'react';
22

3-
import Matter, { Engine, Events } from 'matter-js';
3+
import Matter, {Engine, Events} from 'matter-js';
44

55
export default class World extends Component {
6-
76
static propTypes = {
87
children: PropTypes.any,
98
gravity: PropTypes.shape({
@@ -37,8 +36,12 @@ export default class World extends Component {
3736
};
3837

3938
loop = () => {
40-
const currTime = 0.001 * Date.now();
41-
Engine.update(this.engine, 1000 / 60, this.lastTime ? currTime / this.lastTime : 1);
39+
const currTime = 0.001 * performance.now();
40+
Engine.update(
41+
this.engine,
42+
1000 / 60,
43+
this.lastTime ? currTime / this.lastTime : 1,
44+
);
4245
this.lastTime = currTime;
4346
};
4447

@@ -48,15 +51,15 @@ export default class World extends Component {
4851
this.loopID = null;
4952
this.lastTime = null;
5053

51-
const world = Matter.World.create({ gravity: props.gravity });
54+
const world = Matter.World.create({gravity: props.gravity});
5255

5356
this.engine = Engine.create({
5457
world,
5558
});
5659
}
5760

5861
componentWillReceiveProps(nextProps) {
59-
const { gravity } = nextProps;
62+
const {gravity} = nextProps;
6063

6164
if (gravity !== this.props.gravity) {
6265
this.engine.world.gravity = gravity;
@@ -97,5 +100,4 @@ export default class World extends Component {
97100
</div>
98101
);
99102
}
100-
101103
}

src/native/components/world.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React, { Component, PropTypes } from 'react';
1+
import React, {Component, PropTypes} from 'react';
22

3-
import { View } from 'react-native';
3+
import {View} from 'react-native';
44

5-
import Matter, { Engine, Events } from 'matter-js';
5+
import Matter, {Engine, Events} from 'matter-js';
66

77
export default class World extends Component {
8-
98
static propTypes = {
109
children: PropTypes.any,
1110
gravity: PropTypes.shape({
@@ -39,8 +38,12 @@ export default class World extends Component {
3938
};
4039

4140
loop = () => {
42-
const currTime = 0.001 * Date.now();
43-
Engine.update(this.engine, 1000 / 60, this.lastTime ? currTime / this.lastTime : 1);
41+
const currTime = 0.001 * performance.now();
42+
Engine.update(
43+
this.engine,
44+
1000 / 60,
45+
this.lastTime ? currTime / this.lastTime : 1,
46+
);
4447
this.lastTime = currTime;
4548
};
4649

@@ -50,15 +53,15 @@ export default class World extends Component {
5053
this.loopID = null;
5154
this.lastTime = null;
5255

53-
const world = Matter.World.create({ gravity: props.gravity });
56+
const world = Matter.World.create({gravity: props.gravity});
5457

5558
this.engine = Engine.create({
5659
world,
5760
});
5861
}
5962

6063
componentWillReceiveProps(nextProps) {
61-
const { gravity } = nextProps;
64+
const {gravity} = nextProps;
6265

6366
if (gravity !== this.props.gravity) {
6467
this.engine.world.gravity = gravity;
@@ -95,5 +98,4 @@ export default class World extends Component {
9598
</View>
9699
);
97100
}
98-
99101
}

0 commit comments

Comments
 (0)