Skip to content

Commit 4e858fc

Browse files
committed
rename 'queryHook' to 'queryByHook' per #18
1 parent d300d0f commit 4e858fc

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,13 @@ var view = AmpersandView.extend({
378378
});
379379
```
380380

381-
### queryHook `view.queryHook('hookname')`
381+
### queryByHook `view.queryByHook('hookname')`
382382

383383
A convenience method for retrieving an element from the current view by it's `data-hook` attribute. Using this approach is a nice way to separate javascript view hooks/bindings from class/id selectors that are being used by CSS.
384384

385385
notes:
386-
- It also works if you're using multiple space-separated hooks. So something like `<img data-hook="avatar user-image"/>` would still match for `queryHook('avatar')`.
387-
- It simply uses `.query()` under the hood. So `.queryHook('avatar')` is equivalent to `.query('[data-hook~=avatar]')`
386+
- It also works if you're using multiple space-separated hooks. So something like `<img data-hook="avatar user-image"/>` would still match for `queryByHook('avatar')`.
387+
- It simply uses `.query()` under the hood. So `.queryByHook('avatar')` is equivalent to `.query('[data-hook~=avatar]')`
388388
- It will also match to root elements.
389389
- If no match is found it returns `undefined`.
390390

@@ -395,7 +395,7 @@ var view = AmpersandView.extend({
395395
this.renderWithTemplate(this);
396396

397397
// cache an element for easy reference by other methods
398-
this.imgEl = this.queryHook('avatar');
398+
this.imgEl = this.queryByHook('avatar');
399399

400400
return this;
401401
}

ampersand-view.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ _.extend(View.prototype, {
111111
return res.concat(Array.prototype.slice.call(this.el.querySelectorAll(selector)));
112112
},
113113

114-
// ## queryHook
114+
// ## queryByHook
115115
// Convenience method for fetching element by it's `data-hook` attribute.
116116
// Also tries to match against root element.
117117
// Also supports matching 'one' of several space separated hooks.
118-
queryHook: function (hook) {
118+
queryByHook: function (hook) {
119119
return this.query('[data-hook~="' + hook + '"]');
120120
},
121121

test/main.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ test('renderAndBind with no model', function (t) {
241241
t.end();
242242
});
243243

244-
test('queryHook', function (t) {
244+
test('queryByHook', function (t) {
245245
var View = AmpersandView.extend({
246246
template: '<li data-hook="list-item"><span data-hook="username"></span><img data-hook="user-avatar"/></li>'
247247
});
248248
var view = new View();
249249
view.renderWithTemplate();
250-
t.ok(view.queryHook('username') instanceof Element, 'should find username element');
251-
t.ok(view.queryHook('user-avatar') instanceof Element, 'should find username');
252-
t.ok(view.queryHook('nothing') === undefined, 'should find username');
253-
t.ok(view.queryHook('list-item') instanceof Element, 'should also work for root element');
250+
t.ok(view.queryByHook('username') instanceof Element, 'should find username element');
251+
t.ok(view.queryByHook('user-avatar') instanceof Element, 'should find username');
252+
t.ok(view.queryByHook('nothing') === undefined, 'should find username');
253+
t.ok(view.queryByHook('list-item') instanceof Element, 'should also work for root element');
254254
t.end();
255255
});
256256

0 commit comments

Comments
 (0)