Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to evaluate single, query, or col of script tags. #93

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

chr15m
Copy link
Contributor

@chr15m chr15m commented Nov 23, 2024

Additional PR for #89 to address discussion here: #92

This adds the ability to pass either:

  • a single script tag
  • a col of script tags
  • a querySelectorAll() of tags (NodeList or other JS array-like)
    into scittle.core.eval_script_tags() and have it do the right thing.

Tested like this (with hello.cljs and thing.cljs test scripts in the current dir):

(let [scripts (.querySelectorAll
                js/document
                "script[src='hello.cljs'],script[src='thing.cljs']")
      script (first scripts)]
  (js/console.log "scripts" scripts)
  ; load single tag
  (js/console.log "loading" (-> scripts first (aget "src")))
  (-> js/scittle
      .-core
      (.eval_script_tags script))
  ; load all the tags
  (js/console.log "loading all tags" scripts)
  (-> js/scittle
      .-core
      (.eval_script_tags scripts))
  ; load a js array of the scripts
  (js/console.log "loading all tags as js array")
  (-> js/scittle
      .-core
      (.eval_script_tags (js/Array.from scripts)))
  ; load a native clj seq of the scripts
  (js/console.log "loading all tags as vec")
  (-> js/scittle
      .-core
      (.eval_script_tags [(first scripts) (second scripts)])))

Please answer the following questions and leave the below in as part of your PR.

  • I have updated the CHANGELOG.md file with a description of the addressed issue.

(Update to #89 and discussion so doesn't need a new CHANGELOG.md line I think).

@borkdude borkdude merged commit d23cbc1 into babashka:main Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants