Mounting class declarations
See original GitHub issueHello, I love your library but I am having trouble getting some thing working.
I am using Barba.js as the PJAX library and ideally I would like to import modules that are on the page, call the init()
method and on pageLeave
call the detroy()
method on the module.
Here is what I have so far:
// This is loaded by Barba.js
export class Components {
constructor() {
conditioner.addPlugin({
moduleSetName: name => `./${name}/index.js`,
moduleGetConstructor: module => module.default,
moduleImport: name => import(/* webpackMode: "lazy" */ `${name}`)
});
}
onPageEnter(DOM) {
// lets go!
this.hydrate = conditioner.hydrate(DOM);
}
onPageLeave() {
// Need to destroy the loaded components, unless the are on the new page, in which case I need to reinit them with the new el
}
}
Is there a way to call a Class because when I do it gives me an error saying I can’t call it as a function?
export default ExampleModule {
constructor() { }
init(slider) {
// Init Slider
}
destroy() {
// Destroy Slider
}
}
Some help on this would be amazing!!
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Class declaration - cppreference.com
A class declaration can appear inside the body of a function, in which case it defines a local class. The name of such...
Read more >[Chapter 5] 5.4 Class Declarations
A class declaration creates a reference type in Java. The class declaration also specifies the implementation of the class, including its variables, ...
Read more >React.Component
Mounting. These methods are called in the following order when an instance of a component is being created and inserted into the DOM:...
Read more >class-transformer
This method transforms your class object into a new instance of the class object. This may be treated as deep clone of your...
Read more >3. File Organization
Each Java source file contains a single public class or interface. When private classes and interfaces are ... 3.1.3 Class and Interface Declarations....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Nice, I had to update
moduleGetConstructor
to include.default(element)
to get it working.thanks for the help! I think it’s working now 🎉
Sorry I’m late to the party.
I wanted to share how I’ve been handling a similar situation with a “pjax” library of my own.
I have all my modules in a
modules
folder. There is anindex.js
file that configuresconditioner
and exports ahydrate
and anunmount
function that I call on every page transition. I looks a bit like this:Thank you @rikschennink for such an amazing library.