Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

bulbs-video lazy loading #171

Merged
merged 13 commits into from
Oct 6, 2016
Merged

bulbs-video lazy loading #171

merged 13 commits into from
Oct 6, 2016

Conversation

kand
Copy link
Contributor

@kand kand commented Oct 4, 2016

Implement loadOnDemand wrapper for bulbs-video to lazy load video elements.

Release Type: patch
No large-scale new features, updates should not be breaking.

Updates

  1. bulbs-video now implements loadOnDemand for lazy loading. Lazy loading will occur by default. If this behavior is not necessary for a particular bulbs-video, give the element the disable-lazy-loading attribute to prevent lazy loading.
  2. Stage 2 features for babel activated.

@kand
Copy link
Contributor Author

kand commented Oct 4, 2016

@@ -1,5 +1,5 @@
{
"presets": ["react", "es2015"],
"presets": ["react", "es2015", "stage-2"],
Copy link
Contributor Author

@kand kand Oct 5, 2016

Choose a reason for hiding this comment

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

Allows us to use object spread provided in current es-next Stage 3; babel, for some reason, is currently providing this in stage-2.

let a = {'one': 1};
let b = {'two': 2};
let c = {...a, ...b};
console.log(c);
// outputs: {'one': 1, 'two': 2}

@@ -94,6 +94,8 @@ Use this if developing elements within `bulbs-elements` locally
$ ./scripts/webpack-dev-server
```

You can access the examples site now by visiting [localhost:8080]().
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A helpful note.


if (!allProps.disableLazyLoading) {

return loadOnDemand(BulbsVideoRoot)(allProps);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main change. If the bulbs-video instance has not been provided a disable-lazy-loading property, the video element will be subject to lazy loading.

};

beforeEach(() => {
BulbsVideo.prototype.setState = sinon.spy();
fetchMock.mock(src, {});
subject = new BulbsVideo(props);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this into each context that needs it since we want to delay this instantiation in lazy load tests.

}

requestAnimationFrame(() => {
expect($(container).find('.bulbs-video-root').length).to.equal(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@collin is this the best way we can test this? Doesn't seem to be the best way to do this, but it works.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm not sure of a better way either.

@@ -5,7 +5,6 @@ import VideoMetaRoot from '../elements/meta/components/root';

export default function Cover (props) {
let { video, actions, enablePosterMeta, disableMetaLink } = props;
let imageId = parseInt(video.poster_url.match(/\d+/)[0], 10);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per @collin, this property is no longer used and was throwing errors during tests.

@kand
Copy link
Contributor Author

kand commented Oct 5, 2016

@collin @daytonn @spra85 please review.

Copy link
Contributor

@collin collin left a comment

Choose a reason for hiding this comment

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

Please ask resolve @MichaelButkovic to resolve @spra85's merge conflicts.

@spra85
Copy link
Contributor

spra85 commented Oct 6, 2016

@kand, pulled down the branch and ran the example and I see both requests for clickhole.json firing on page load. Should we be waiting to dispatch the request for the video metadata until it's in view?

@collin
Copy link
Contributor

collin commented Oct 6, 2016

Ah, bit of a trick that.

We could extend the loadOnDemand wrapper to check on thedisableLazyLoading` prop.

Changing this:

export default function loadOnDemand (component) {
  const wrapped = (props) => { // eslint-disable-line react/no-multi-comp
    return (
      <LoadOnDemand
        component={component}
        componentProps={props}
      />
    );
  };

...to something like:

export default function loadOnDemand (Component) {
  const wrapped = (props) => { // eslint-disable-line react/no-multi-comp
    if (props. disableLazyLoading) {
      return <Component ...props/>;
    }
    return (
      <LoadOnDemand
        component={Component}
        componentProps={props}
      />
    );
  };

Then the bulb-video definition could change to someting like:

registerReactElement('bulbs-video', loadOnDemand(BulbsVideo);

@kand
Copy link
Contributor Author

kand commented Oct 6, 2016

@collin @spra85 that'll work, that way the disable lazy loading code/attribute will be reusable. I'll implement that solution with tests.

@collin
Copy link
Contributor

collin commented Oct 6, 2016

👍

@kand
Copy link
Contributor Author

kand commented Oct 6, 2016

@collin @spra85 @daytonn alright, ready for review again.

@kand kand merged commit 0012be5 into master Oct 6, 2016
@kand kand deleted the bulbs-video-lazy-load branch October 6, 2016 21:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants