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

Simplified component declaration #1

Closed
anton-github opened this issue Sep 27, 2019 · 3 comments
Closed

Simplified component declaration #1

anton-github opened this issue Sep 27, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@anton-github
Copy link
Collaborator

anton-github commented Sep 27, 2019

Currently we have two types of data-attributes: data-dc-component-{namespace} and data-dc-{namespace}-{name}.
First one (let's call it "anchor" attribute) is only to connect nodes with previously registered classes and create new classes instances on those nodes.
The purpose of the second one is to connect attributes to a specific component. The {name} can be whatever you want, the examples are the built in attributes like data-dc-{namespace}-ref and data-dc-{namespace}-options.

So in order to simplify declaration we can do 2 things:

  • Instead of using data-dc-{namespace}-options to pass some options to the component and automatically parse it as JSON we can use "anchor" attribute itself. So the declaration will change from this:
<div data-dc-component-collapsed
       data-dc-collapsed-options='{"speed": 500, "ease": "linear"}'>
</div>

to this:

<div data-dc-component-collapsed='{"speed": 500, "ease": "linear"}'>
</div>
  • To remove the "component" word from data-dc-component-{namespace} so anchor attribute from the example above will look like this data-dc-collapsed



I like the first one because we will be able to easy declare small utility components like gtm triggers:

<div data-dc-component-gtm='{"category":"Selling", "action":"Promo", "label":"Discover a new perspective"}'>
</div>

The second one makes declaration even shorter but has drawback which is we will be limited in naming components because two types of attributes can intersect each other.
For example, I have component named "modal" and I want to create component named "modal-ref". If "modal-ref" will be placed inside "modal" it will be treated not only as a component but also as ref of the "modal" component as they will have the same declaration: data-dc-modal-ref.

Any thoughts?

@anton-github anton-github added the enhancement New feature or request label Sep 27, 2019
@anton-github anton-github self-assigned this Sep 27, 2019
@bububo
Copy link
Collaborator

bububo commented Sep 27, 2019

I like the second option
<div data-dc-gtm='options'></div>

If you create a component with name data-dc-some-ref it is your choice. As I understand, all will still work. There will be just one redundant ref in the componentdata-dc-some.

@anton-github
Copy link
Collaborator Author

@bububo Whether or not it will still be working will totally depend on particular component which will get an unexpected ref. But essentially yes, I agree, it's not that critical.

@anton-github
Copy link
Collaborator Author

Declarations has been change and available in version 1.0.0
Release https://github.com/Delete-Agency/dc/releases/tag/v1.0.0

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

2 participants