This repository has been archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Chaining #1
Comments
This might be less error prone: function View(el) { this.el = el; }
require('mdom/closest/mixin')(View); Would be something like: var closest = require('mdom/closest');
module.exports = function (View) {
View.prototype.closest = function (selector) {
return new View(closest(this.el, selector));
};
return View;
}; |
This is a random idea but throwing it out there. var sequence = require('mdom/sequence')
.....
var myHardToFindElement = sequence(document.querySelector('.baseQueryClass'), [
parents('tr'),
siblings(':not(even)'),
children('td')
]); As long as each call in sequence returns a node or nodeList - it should be passed as an implied first argument to the next call. |
I really like this idea. It's more consistent with the direction var q = require('q');
var get = require('mjax/get');
q(document.querySelector('[data-model]'))
.then(first('[data-controller]'))
.then(function(el) {
return get(el.dataset.url);
})
.then(function(data) {
return document.querySelector(data.target);
})
.then(container('.js-obscure-element'))
.then(function(el) { ... }); |
Perhaps a bit more useful example: Array.prototype.forEach
.call(document.querySelectorAll('.thumbnail'), addClass('foo')); |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
mdom
is basically wrappers that mimic jquery's apis around any Node or NodeList really. So:Becomes:
The big downside to this pattern is loss of chaining. We end up back in lisp land with a bunch of close-paren soup. I don't think there's a good way to get around that if each method is supposed to return a Node or NodeList.
I wonder if we can come up with a mixin pattern.
Would be a shortcut for something like:
Kind of a byo$.
The text was updated successfully, but these errors were encountered: