diff options
author | Johan Vosloo <jvosloo@gmail.com> | 2020-12-26 22:58:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-26 22:58:17 +0100 |
commit | 19b436773dd66bfb2e83ef60e355a15e219b9d7d (patch) | |
tree | 3bb2130e7d31f99f95ea8cb5f1b736e90ebb3242 /src/ext/path-deps.js | |
parent | 5fd24a7096a0ecba6478fd6a06de1e321b65aab9 (diff) | |
download | htmx-19b436773dd66bfb2e83ef60e355a15e219b9d7d.tar.gz htmx-19b436773dd66bfb2e83ef60e355a15e219b9d7d.zip |
Update path-deps.js
By catering for a new custom event called `htmx:refreshPath`, we should be able to support the triggering of the refresh of a specific path
Diffstat (limited to 'src/ext/path-deps.js')
-rw-r--r-- | src/ext/path-deps.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/ext/path-deps.js b/src/ext/path-deps.js index e1264e79..b247197b 100644 --- a/src/ext/path-deps.js +++ b/src/ext/path-deps.js @@ -15,20 +15,26 @@ return false; } + function refreshPath(path) { + var eltsWithDeps = htmx.findAll("[path-deps]"); + for (var i = 0; i < eltsWithDeps.length; i++) { + var elt = eltsWithDeps[i]; + if (dependsOn(elt.getAttribute('path-deps'), path)) { + htmx.trigger(elt, "path-deps"); + } + } + } + htmx.defineExtension('path-deps', { onEvent: function (name, evt) { if (name === "htmx:afterRequest") { var config = evt.detail.requestConfig; // mutating call if (config.verb !== "get") { - var eltsWithDeps = htmx.findAll("[path-deps]"); - for (var i = 0; i < eltsWithDeps.length; i++) { - var elt = eltsWithDeps[i]; - if (dependsOn(elt.getAttribute('path-deps'), config.path)) { - htmx.trigger(elt, "path-deps"); - } - } + refreshPath(config.path); } + } else if (name === "htmx:refreshPath") { + refreshPath(evt.path); } } }); |