Comments (9)
I believe it is intended, the initial page load is also a DOM load so it makes sense. Any bindings that need to happen after Intercooler swaps content should also happen when the page first loads.
Can you post a specific example where your having issues? I may be able to help.
from intercooler-js.
@adamstep I was under impression for Inetrcooler.ready
to trigger DOM needs to load through Intercooler, not any other way.
So does it mean that DOM loaded through other means will also trigger Intercooler.ready
? I'm talking about something like this:
let request = $.get("~/myEndpoint");
request.done(function (html: string) {
$('#reloadme').append(html);
});
As for concrete proglem, it is element double binding. We have a function that binds all the elements that needs binding, something like BindAllElements(selector)
where it goes through selector and does the bindings. On document.ready
we call BindAllEmenents('body')
.
And then every time we reload parts of pages we call BindAllElements('#reloadme')
.
Now we are trying out Intercooler on small part of our application and do this:
Intercooler.ready(function (rootContent) {
BindAllElements(rootContent.selector)
});
When the page is loaded it effectively calls BindAllElements('body')
for the second time, after we already done that first binding. Thus causing double bindings on elements.
For now I've worked around like this:
Intercooler.ready(function (rootContent: any) {
if (rootContent[0].tagName !== "BODY") {
BindAllElements(rootContent.selector)
}
});
But this feels very hacky, hence my question here.
from intercooler-js.
I think this is a case of the docs not matching the intent. The reference page does indeed say " to be run on the top level of all content that is swapped into the DOM by intercooler." However, I've always thought of it as simply meaning "when Intercooler is ready," i.e. Intercooler has processed all the elements on the page (either when first loaded or when swapped in). In your example, I would simply get rid of the document.ready
and eliminate the if
inside Intercooler.ready
.
Can we consider this a documentation bug and fix the wording rather than changing the behavior (which other Intercooler apps already depend on)?
from intercooler-js.
Yeah, this isn't documented that well and needs a fix.
Basically Intercooler.ready
is the intercooler replacement for $.ready
, except you have to do all initialization within the elt
passed in, rather than globally as you would with $.ready
.
from intercooler-js.
I wanted to have one place where you did your initialization code for both the initial body load as well as any AJAX calls.
from intercooler-js.
from intercooler-js.
Hello Anders,
By element bindings I mean our elements, not Intercooler's. We use KendoUI for datepickers, colourpickers, etc. We need to tell Kendo what should be a datepicker, what should be a colour picker, etc. So we have loads of bits of code that do:
$selector.find('input.datep').kendoDatePicker({
format: "dd/MM/yyyy"
});
$selector.find('input.datetimep').kendoDateTimePicker({
format: "dd/MM/yyyy HH:mm"
});
$selector.find('input.colorPicker').kendoColorPicker();
// etc.
When new bits of DOM are loaded we need to execute those binders on the new elemenets, otherwise Kendo does not pick it up. As far as I can see Intercooler.processNodes
only deals with Intercooler bindings, nothing external. Hence the usage of Intercooler.ready
.
As for replacing $.ready
with Intercooler.ready
- we can't do that, as we have hundreds of pages where sometimes we are binding page-specific elements retest or rewrite all those pages is not an option.
So if you are saying this is an intended behaviour, we'll just keep what we have with the test for BODY. Unless there is a better way you can suggest.
Thanks for looking into this!
from intercooler-js.
from intercooler-js.
@baumann74
I see, I'll give this a try, but I sense repeating the binding code on every partial page smells of DRY violation.
Thank you for your time and help on this, very much appreciated!
Cheers,
Max
from intercooler-js.
Related Issues (20)
- simple Django - Intercooler.js example on how to pass a django variable to a view HOT 2
- It appears the google group is gone HOT 4
- Default values not displayed on refresh HOT 5
- IC potential clash with jquery ? HOT 2
- Set history and new URL after ic-get-from? HOT 3
- Suggest clarification on `ic-target` HOT 1
- How get and populate different targets with a single POST request HOT 3
- Can ic-get-from include value of triggered input? HOT 2
- Prepend element before a target and remove element afterwards HOT 5
- Query string keeps getting bigger ic-get-from / ic-current-url HOT 1
- Preventing default for a button inside a form HOT 4
- ic-push-params: multiple GET parameters with same name cannot be pushed to URL HOT 1
- Elements with SSE trigger do not get cleaned up when swapped out of the DOM HOT 6
- ic-action does not support chained derefences HOT 5
- New add-object form includes a dependent select HOT 2
- document bootstrap version on example(s)
- intercooler-1.1.1.min.js offline HOT 3
- ic-trigger-from not working on form with ic-post-to HOT 1
- Extending the functionality of Intercooler to other controls
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intercooler-js.