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

Allow renaming on: prefix for conditions #16

Open
drevantonder opened this issue Dec 9, 2022 · 3 comments
Open

Allow renaming on: prefix for conditions #16

drevantonder opened this issue Dec 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@drevantonder
Copy link

The prefix for conditions on: is currently "hardcoded" in the Conditions.getConditions method:

class Conditions {
  /* ... */
 static getConditions(node) {
    let map = {};
    for(let key of Object.keys(Conditions.map)) {
      if(node.hasAttribute(`on:${key}`)) {
        map[key] = node.getAttribute(`on:${key}`);
      }
    }
 }
 /* ... */
}

Would it be possible for <is-land> to allow renaming that prefix?


A use-case for this is when other frameworks interpret on: as something else. For example (and in our case), Vue when specifying listeners using render functions interprets on followed by a capital letter (in this case :) as a listener:

h(
  'is-land',
  {
    'on:visible' : ''
  }
)

Will render:

<is-land></is-land>

Happy to work on this and create a pull request. See main...cmiteam:is-land:main for what I've already done.

Thanks for creating <is-land>!

@JoshTheDerf
Copy link

Thanks @drevantonder! Yep, this would be particularly useful when embedding is-land inside of SSR'd page using Vue (or similar framework).

@zachleat
Copy link
Member

Sorry for the late reply here, what would the app usage look like if something like main...cmiteam:is-land:main were implemented?

I think I’m supportive, I’d love to see the : colon wrapped into the prefix too so that folks wouldn’t have to use that if they didn’t want

@zachleat zachleat added the enhancement New feature or request label Jan 10, 2023
@drevantonder
Copy link
Author

drevantonder commented Jan 12, 2023

I wasn't sure how <is-land> was intended to be initialized/configured, but what worked for me was to export an initIslands function that would allow users to set both the tag and prefix of <is-land> like so:

import { initIslands } from '@11ty/is-land'

initIslands({
 tag: 'awesome-is-land',
 conditionsPrefix: 'when:'
])
<awesome-is-land when:idle>...</awesome-is-land>

I've moved the colon : into Conditions.prefix in 68da03c. 👍


Feel free to pick, choose, or throw out the changes I've made at cmiteam/is-land. I'm also happy to open a pull request for what we have there (not much 😅).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants