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

Element getters? #175

Open
fractaledmind opened this issue Feb 28, 2016 · 2 comments
Open

Element getters? #175

fractaledmind opened this issue Feb 28, 2016 · 2 comments

Comments

@fractaledmind
Copy link

Lea,

Once again, a great library. Thank you so much for this! :)

I was wondering if you would be amenable to having the functions defined under $.setProps be written to work as both "getters" and "setters"? By this I simply mean that if you pass a param to the function (e.g. Bliss.properties(subject, props) or subject._.properties(props)) it functions as a "setter", but if you simply call the function without a param (e.g. Bliss.properties(subject) or subject._.properties()) it functions as a "getter".

My initial implementation is fairly rudimentary, but it has worked for the use-cases I have. I am simply checking for the existence of the single param and splitting the functionality into two code paths accordingly. To take properties as a simple example:

properties: function (val) {
    if(val) {
      $.extend(this, val);
    }
    else {
      return $.extend({}, this);
    }
}

Obviously, not every function in $.setProps can have both a "getter" and a "setter", but plenty could. And I think the functionality would be quite helpful (I personally need "getters" for attributes and properties).

Once again, thank you for all of your hard work,
stephen

@LeaVerou
Copy link
Owner

Not sure about this. How often do people need to get ALL properties or ALL attributes from an element? It seems like a special case to me, and as you pointed out, it can already be done in 1 line (for attributes just do $$(this.attributes).map(attribute => attribute.name)). We should be mindful of bloat, otherwise we'll end up with yet another bloated library.
What do others think?

@LeaVerou
Copy link
Owner

That said, Bliss should be extensible enough to allow third party devs to do this via plugins. We already have a hooks system, though it cannot intercept the return value, so maybe we should work on that.

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

No branches or pull requests

2 participants