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

Searcher #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ui-components/range-filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
);
}


// it should save the parameters 'nodes' and 'listeners'
// as internal properties of the instance for later use
// it should also register the corresponding listeners to the DOM
Expand Down Expand Up @@ -92,4 +91,4 @@
};

uiComponents.RangeFilter = RangeFilter;
});
});
43 changes: 39 additions & 4 deletions ui-components/searcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
}
}


// it should return an array like the following
// [
// {
Expand All @@ -37,6 +36,20 @@
// }
// }
// ]
// [
// {
// node: SearchButton,
// listeners: {
// 'click': onSearchButtonClicked
// }
// },
// {
// node: node2,
// listeners: {
// eventName2: listenerWithPartialApplication2
// }
// }
// ]
// the first node should be the one corresponding to the search button
// the first event name should be the 'click' event and its
// listener should be 'onSearchButtonClicked' with partial application
Expand All @@ -47,6 +60,21 @@
// listener should be 'onSearchKeyPressed' with partial application
// of the 'listeners.keypress' parameter
function getDomListeners(nodes, listeners) {

return [
{
node: nodes.searchButton,
'listeners': {
'click' : onSearchButtonClicked.bind(undefined, nodes.searchButton, listeners.search)
}
},
{
node: nodes.searchInput,
'listeners': {
'keypress' : onSearchKeyPressed.bind(undefined, nodes.searchButton, listeners.search)
}
}
]
}

function ensureListeners(listeners) {
Expand All @@ -73,25 +101,32 @@
);
}


// it should save the 'listeners' parameters as internal
// state of the instance
// it should also register those listeners into the DOM
// hint: the ui module has a util method for registering listeners
// hint2: use the result of the internal method 'getDomListeners'
// to invoke the ui method
function Searcher(nodes, listeners) {

ensureNodes(nodes);
ensureListeners(listeners);

//// add code here ////
this.nodes = nodes;
this.listeners = getDomListeners(nodes, listeners);

utils.registerDomListeners(this.listeners);
}

// it should remove the listeners added on the constructor
// hint: the ui module has a util method for removing listeners
Searcher.prototype.destroy = function() {
utils.unregisterDomListeners(this.listeners);
};

Searcher.prototype.getValue = function() {
return this.nodes.searchInput.value;
};

uiComponents.Searcher = Searcher;
});
});