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

Commit ae40ee7

Browse files
authored
Merge pull request #27 from kwelch/remove-date-now
Replace date.now with performance.now
2 parents a50338f + 8f24e83 commit ae40ee7

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/components/world.js

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

4-
import Matter, { Engine, Events } from 'matter-js';
4+
import Matter, {Engine, Events} from 'matter-js';
55

66
export default class World extends Component {
7-
87
static propTypes = {
98
children: PropTypes.any,
109
gravity: PropTypes.shape({
@@ -38,8 +37,12 @@ export default class World extends Component {
3837
};
3938

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

@@ -49,15 +52,15 @@ export default class World extends Component {
4952
this.loopID = null;
5053
this.lastTime = null;
5154

52-
const world = Matter.World.create({ gravity: props.gravity });
55+
const world = Matter.World.create({gravity: props.gravity});
5356

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

5962
componentWillReceiveProps(nextProps) {
60-
const { gravity } = nextProps;
63+
const {gravity} = nextProps;
6164

6265
if (gravity !== this.props.gravity) {
6366
this.engine.world.gravity = gravity;
@@ -98,5 +101,4 @@ export default class World extends Component {
98101
</div>
99102
);
100103
}
101-
102104
}

src/native/components/world.js

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

4-
import { View } from 'react-native';
4+
import {View} from 'react-native';
55

6-
import Matter, { Engine, Events } from 'matter-js';
6+
import Matter, {Engine, Events} from 'matter-js';
77

88
export default class World extends Component {
9-
109
static propTypes = {
1110
children: PropTypes.any,
1211
gravity: PropTypes.shape({
@@ -40,8 +39,12 @@ export default class World extends Component {
4039
};
4140

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

@@ -51,15 +54,15 @@ export default class World extends Component {
5154
this.loopID = null;
5255
this.lastTime = null;
5356

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

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

6164
componentWillReceiveProps(nextProps) {
62-
const { gravity } = nextProps;
65+
const {gravity} = nextProps;
6366

6467
if (gravity !== this.props.gravity) {
6568
this.engine.world.gravity = gravity;
@@ -96,5 +99,4 @@ export default class World extends Component {
9699
</View>
97100
);
98101
}
99-
100102
}

0 commit comments

Comments
 (0)