Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

changed debounce out for bindRaf #14

Merged
merged 3 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
node_modules
build
npm-debug.log
bundle.js
bundle.js

# ide folders
.idea

# for now removing package-lock as it's not my decision to include
package-lock.json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, we should pin this somehow.

4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import debounce from './lib/debounce';
import { bindRaf } from "./lib/bindRaf";
Copy link
Owner

@dazld dazld Oct 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use kebab case for file names?


class OnVisible extends Component {
constructor() {
super(...arguments);
this.onScroll = debounce(this.onScroll.bind(this), 10);
this.onScroll = bindRaf(this.onScroll.bind(this));
this.state = {
visible: false,
bottom: 0,
Expand Down
22 changes: 22 additions & 0 deletions src/lib/bindRaf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const bindRaf = (fn) => {
let isRunning = null;
let self = null;
let args = null;

const run = () => {
isRunning = false;
fn.apply(self, args);
};

return () => {
self = this;
args = arguments;

if (isRunning) {
return;
}

isRunning = true;
requestAnimationFrame(run);
};
};
9 changes: 0 additions & 9 deletions src/lib/debounce.js

This file was deleted.