Skip to content

Commit

Permalink
Update hooks signature
Browse files Browse the repository at this point in the history
  • Loading branch information
JanPetr committed Sep 28, 2018
1 parent 09c0a16 commit 8784e24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"description": "Custom boilerplate module to extend Algolia Magento 2 extension",
"type": "magento2-module",
"license": ["MIT"],
"version": "1.0.0",
"version": "1.0.1",
"require": {
"algolia/algoliasearch-magento-2": "@dev"
"algolia/algoliasearch-magento-2": ">=1.7.0@dev"
},
"autoload": {
"files": [ "registration.php" ],
Expand Down
34 changes: 21 additions & 13 deletions view/frontend/web/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,55 @@
* autocomplete.js documentation: https://github.com/algolia/autocomplete.js
**/

function algoliaHookBeforeAutocompleteStart(sources, options, algoliaClient) {
console.log('In hook method to modify autocomplete instance');
algolia.registerHook('beforeAutocompleteSources', function(sources, algoliaClient) {
console.log('In hook method to modify autocomplete data sources');

// Modify default sources and options
// Modify autocomplete data sources

return [sources, options];
}
return sources;
});

algolia.registerHook('beforeAutocompleteOptions', function(options) {
console.log('In hook method to modify autocomplete options');

// Modify autocomplete options

return options;
});

/**
* InstantSearch hook methods
* IS.js documentation: https://community.algolia.com/instantsearch.js/v2/getting-started.html
**/

function algoliaHookBeforeInstantsearchInit(instantsearchOptions) {
algolia.registerHook('beforeInstantsearchInit', function(instantsearchOptions) {
console.log('In method to modify instantsearch options');

// Modify instant search options

return instantsearchOptions;
}
});

function algoliaHookBeforeWidgetInitialization(allWidgetConfiguration) {
algolia.registerHook('beforeWidgetInitialization', function(allWidgetConfiguration) {
console.log('In hook method to modify instant search widgets');

// Modify instant search widgets

return allWidgetConfiguration;
}
});

function algoliaHookBeforeInstantsearchStart(search) {
algolia.registerHook('beforeInstantsearchStart', function(search) {
console.log('In hook method to modify instant search instance before search started');

// Modify instant search instance before search started

return search;
}
});

function algoliaHookAfterInstantsearchStart(search) {
algolia.registerHook('afterInstantsearchStart', function(search) {
console.log('In hook method to modify instant search instance after search started');

// Modify instant search instance after search started

return search;
}
});

0 comments on commit 8784e24

Please sign in to comment.