Message from JavaScript discussions

November 2020

— Was making some infinite thing, then, read some Babich man https://uxplanet.org/ux-infinite-scrolling-vs-pagination-1030d29376f1#.lprju4x15

Message permanent page

— 

He says infinite won't be effective for e-shop catalog, anyway i did some thing but he's mostly right

— I found this one very useful

— Https://github.com/anseki/gnirts

— Hi,
What are some strategies to get rid of circular dependencies

— Dependency injection

— Is there an example you can provide?

— By moving all your dependencies into the function signature, you can resolve the dependencies top-down from the root of your application. I've written in-depth about this here: https://happy-css.com/articles/dependency-injection-in-java-script/

Message permanent page

— Let me check that out

— Not only do you avoid recursive dependencies, but you also open up to a lot of other flexibility goodies.. Like testing (mockability), you can wrap dependencies to your liking to add more functionality (e.g. a logger attached to fs.writeFile calls) there are many possibilities. It might look like a bit too much code, but you will soon appreciate the flexibility.

Message permanent page

— It works like that:

// index.js
const dependencies = {
a: require('./a'),
b: require('./b'),
}

// a.js
module.exports = dependencies => ({
getFile: () => 'filename',
save: () => {
dependencies.b(dependencies).whatever()
}

})

// b.js
module.exports = dependencies => ({
whatever: () => dependencies
.a(dependencies).getFile()
})

Message permanent page

— This is better viewed here: https://runkit.com/martinmuzatko/5fb27e910c4e54001abe8221