Skip to content

Feature: Debounced/delayed Loading #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Aug 5, 2018
Merged

Conversation

fpapado
Copy link
Owner

@fpapado fpapado commented Aug 5, 2018

Closes #10, and cleans up the codebase.

(See the issue for the design discussion)

Re-architect the internals to have explicit state management, in the spirit of Elm. The various state transitions go between NotAsked -> Buffering -> NotAsked | Loading -> LoadingSuccess | LoadingError, with actions for Buffering, Going In/Out of view, Loading results etc.

External API:
An optional debounceDurationMs prop.

<LazyImage
  src="/img/porto_buildings_large.jpg"
  alt="Buildings with tiled exteriors, lit by the sunset."
  debounceDurationMs={1000}
  placeholder={({ imageProps, ref }) => (
    <img ref={ref} src="/img/porto_buildings_lowres.jpg" alt={imageProps.alt} />
  )}
  actual={({ imageProps }) => <img {...imageProps} />}
/>

fpapado added 26 commits July 22, 2018 12:46
Not sure where the reducer/update function is headed, but we'll
find out, I suppose.
It works, but now the intersection logic is not the same. Scrolling
until inView is true, and then up, triggers the promise cancelation.
This is undesirable. We want the image to keep loading as long as
it stays on the screen. Oddly, scrolling past the image, and it
being in view, still lets it load without canceling (as intendeed).
Another difference is that loading only commences once the image is
fully in view, rather than on the margin.
Added:
- debugActions: logs actions in dev, warns and logs in prod
- debounceDurationMs: whether, and how much to debounce loading,
  0 by default, so no change to v1. Added codepath to make it so.
- Provisional changes.md document with API compatibility
- Various TODOs and cleanup tasks
Also add a note to hopefully remember to destructure next time :)
If we set declaration: true, then typescript (specifically rpt2,
Rollup's TS plugin) fails with a cryptic path error. This is
filed under microsoft/TypeScript#25047.

Curiously, this does not happen on master, and I have vaguely
traced it back to unionize and the fact that it does fancy type
exports, which we partially re-export here. We would have to
manually emit a declaration file, which is not hard tbh, but a bit
annoying. Even funnier, webpack has no issue building in storybook,
but that might be because it does not emit declarations anyway.

Steps:
- Get declaration file from master, add to repository, and copy to
dist/ upon build;
- See if massaging our exports fixes it;
- Wait for TS :/
The Elm/JS/Redux/React-Component fusion is complete. The reducer
is now a pure function, because it only describes side-effects,
and does not execute them. The logic is really nice to read there.
Because of the "path undefined" bug, we have to run `tsc`
separately, to get the definitions and copy them over.
Expose it under 'Loading' for backwards compatibility
@fpapado fpapado merged commit a68ffac into master Aug 5, 2018
@fpapado fpapado deleted the feature-delayed-loading branch August 5, 2018 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant