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

feat: implement service worker example #3374

Merged
merged 10 commits into from
Nov 27, 2020
Merged

Conversation

Gozala
Copy link
Contributor

@Gozala Gozala commented Nov 7, 2020

Adds example demonstrating how to use IPFS node in shared worker from service worker.

@achingbrain
Copy link
Member

It looks like the test for the new example-browser-service-worker example is failing?

@achingbrain
Copy link
Member

There's a webpack error before the test runs:

example-browser-service-worker: [webpack-cli] [Error: ENOTDIR: not a directory, open '/home/travis/build/ipfs/js-ipfs/examples/browser-service-worker/dist/main.js'] {
example-browser-service-worker:   errno: -20,
example-browser-service-worker:   code: 'ENOTDIR',
example-browser-service-worker:   syscall: 'open',
example-browser-service-worker:   path: '/home/travis/build/ipfs/js-ipfs/examples/browser-service-worker/dist/main.js'
example-browser-service-worker: }

@Gozala
Copy link
Contributor Author

Gozala commented Nov 9, 2020

@achingbrain fixed it all passes now, was just a typo in test scripts where I had & instead of &&.

Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

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

There's an awful lot of boilerplate code here, it's not terribly clear what the minimal set of code needed to get a shared worker going is and what is window dressing.

It also uses a lot of technology that may not be absolutely essential and as such are distractions. People look at these examples without a 100% understanding of TypeScript, Webpack, Babel, even JavaScript so anything that can be removed should be removed.

E.g. People will largely copy/paste the example and use it to start a new project. Ask yourself what tech choices have you then made for them? Maybe don't make those choices. For example if we can get away with just using a script tag and linking to node_modules/some-module/dist/index.min.js instead of using a bundler, do that instead - it'll make the example more concise (good for the reader) and more maintainable since there will be fewer dependencies to be constantly upgrading (good for us).

Could you please restructure the example to show clearly what is boilerplate/unnecessary and what is not.

examples/browser-service-worker/webpack.config.js Outdated Show resolved Hide resolved
examples/browser-service-worker/test.js Outdated Show resolved Hide resolved
examples/browser-service-worker/README.md Outdated Show resolved Hide resolved
examples/browser-service-worker/README.md Outdated Show resolved Hide resolved
examples/browser-service-worker/README.md Outdated Show resolved Hide resolved
examples/browser-service-worker/src/service.js Outdated Show resolved Hide resolved
examples/browser-service-worker/src/service.js Outdated Show resolved Hide resolved
examples/browser-service-worker/src/service.js Outdated Show resolved Hide resolved
examples/browser-service-worker/src/service.js Outdated Show resolved Hide resolved
@Gozala Gozala requested a review from achingbrain November 12, 2020 19:35
@Gozala
Copy link
Contributor Author

Gozala commented Nov 12, 2020

@achingbrain as per our discussion I have moved some pieces into utils and added a general overview section into readme that attempts to provide guidence in terms of how to navigate the code base.

Gozala and others added 3 commits November 23, 2020 09:58
Co-authored-by: Alex Potsides <alex@achingbrain.net>
- Gate calls to ipfs.cat with ipfs.stat
- Make streaming dir renderring and add a limit
@Gozala Gozala requested a review from achingbrain November 25, 2020 21:49
@Gozala
Copy link
Contributor Author

Gozala commented Nov 25, 2020

@achingbrain I have addressed remaining notes

  • instead of error base dir rendering fallback callback now code uses ipfs.file.stat to choose between dir & file renderring.
    • There are still some error handling e.g. to redirect non file / dir entries to https://explore.ipld.io for the nodes
  • dir renderring no longer buffers but rather streams response.
    • Both chrome and firefox seem to do incremental rendering of entries
    • I have added limit to the number of entries, if limit is reached note about pagination user exercise is renderred

@achingbrain achingbrain merged commit 19e5d4c into master Nov 27, 2020
@achingbrain achingbrain deleted the feat/service-worker-example branch November 27, 2020 15:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants