From 5057297161c7fa7e9c7f58b50c04c8dfe9d3e5f7 Mon Sep 17 00:00:00 2001 From: Shahmir Ejaz Date: Tue, 8 Oct 2024 11:22:05 +0100 Subject: [PATCH] refactor: remove string templates (#495) --- .../autocomplete-results-page/src/app.js | 6 ++-- .../conditional-request/src/app.js | 12 +++---- .../facet-dropdown/src/Dropdown.js | 6 ++-- instantsearch.js/facet-dropdown/src/app.js | 6 ++-- .../geo-search-custom-marker/src/app.js | 4 +-- .../geo-search-tourism/src/app.js | 34 +++++++++---------- instantsearch.js/multi-index-hits/src/app.js | 6 ++-- instantsearch.js/query-suggestions/src/app.js | 6 ++-- .../refresh-cache-periodically/src/app.js | 10 +++--- .../refresh-cache-user-action/src/app.js | 22 ++++++------ instantsearch.js/routing-basic/src/app.js | 4 +-- .../routing-seo-friendly/src/app.js | 4 +-- instantsearch.js/secured-api-keys/src/app.js | 10 +++--- instantsearch.js/segment-connector/src/app.js | 19 +++++------ 14 files changed, 71 insertions(+), 78 deletions(-) diff --git a/instantsearch.js/autocomplete-results-page/src/app.js b/instantsearch.js/autocomplete-results-page/src/app.js index 1eeffd0cdb..9ffcaa5fc3 100644 --- a/instantsearch.js/autocomplete-results-page/src/app.js +++ b/instantsearch.js/autocomplete-results-page/src/app.js @@ -57,13 +57,13 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` + item: (hit, { html, components }) => html`
- {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'name' })}

- {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'description' })}

`, diff --git a/instantsearch.js/conditional-request/src/app.js b/instantsearch.js/conditional-request/src/app.js index 3ec7b2c790..b5235189ce 100644 --- a/instantsearch.js/conditional-request/src/app.js +++ b/instantsearch.js/conditional-request/src/app.js @@ -35,15 +35,13 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - empty: ` - {{#query}} - No results for {{query}} - {{/query}} + empty: ({ query }, { html }) => html` + No results for ${query} `, - item: ` + item: (hit, { html, components }) => html`
-

{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}

-

{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}

+

${components.Highlight({ hit, attribute: 'name' })}

+

${components.Highlight({ hit, attribute: 'description' })}

`, }, diff --git a/instantsearch.js/facet-dropdown/src/Dropdown.js b/instantsearch.js/facet-dropdown/src/Dropdown.js index fce4582629..74a7aceb57 100644 --- a/instantsearch.js/facet-dropdown/src/Dropdown.js +++ b/instantsearch.js/facet-dropdown/src/Dropdown.js @@ -35,7 +35,7 @@ export function createDropdown( const makeWidget = instantsearch.widgets.panel({ cssClasses, templates: { - header: options => { + header: (options, { html }) => { const { widgetParams } = options; let text; @@ -67,13 +67,13 @@ export function createDropdown( classNames.push(cssClasses.buttonRefined); } - return ` + return html` `; }, - footer: ``, + footer: (_, { html }) => html``, }, })(baseWidget); diff --git a/instantsearch.js/facet-dropdown/src/app.js b/instantsearch.js/facet-dropdown/src/app.js index 866a6fe58b..c797bea82d 100644 --- a/instantsearch.js/facet-dropdown/src/app.js +++ b/instantsearch.js/facet-dropdown/src/app.js @@ -69,10 +69,10 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` + item: (hit, { html, components }) => html`
-

{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}

-

{{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}}

+

${components.Highlight({ hit, attribute: 'name' })}

+

${components.Highlight({ hit, attribute: 'description' })}

`, }, diff --git a/instantsearch.js/geo-search-custom-marker/src/app.js b/instantsearch.js/geo-search-custom-marker/src/app.js index 0f325db05a..68eac11f35 100644 --- a/instantsearch.js/geo-search-custom-marker/src/app.js +++ b/instantsearch.js/geo-search-custom-marker/src/app.js @@ -24,9 +24,9 @@ injectScript( container: '#maps', googleReference: window.google, templates: { - HTMLMarker: ` + HTMLMarker: (hit, { html }) => html` - {{ city }} - {{ airport_id }} + ${hit.city} - ${hit.airport_id} `, }, diff --git a/instantsearch.js/geo-search-tourism/src/app.js b/instantsearch.js/geo-search-tourism/src/app.js index ccc9b0d0b2..a9ef8778f7 100644 --- a/instantsearch.js/geo-search-tourism/src/app.js +++ b/instantsearch.js/geo-search-tourism/src/app.js @@ -35,23 +35,23 @@ $script( instantsearch.widgets.hits({ container: '#hits', templates: { - item: - '
' + - '
' + - '' + - '' + - '
' + - '
' + - '

{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}

' + - '

' + - '{{room_type}} - ' + - '{{#helpers.highlight}}{ "attribute": "city" }{{/helpers.highlight}},' + - '{{#helpers.highlight}}{ "attribute": "country" }{{/helpers.highlight}}' + - '

' + - '
' + - '
', - empty: - '
No results found matching {{query}}.
', + item: (hit, { html, components }) => html` +
+
+ + +
+
+

${components.Highlight({ hit, attribute: 'name' })}

+

+ ${hit.room_type} - ${components.Highlight({ hit, attribute: 'city' })}, ${components.Highlight({ hit, attribute: 'country' })} +

+
+
' + `, + empty: ({ query }, { html }) => html` +
No results found matching ${query}.
+ ` }, }), diff --git a/instantsearch.js/multi-index-hits/src/app.js b/instantsearch.js/multi-index-hits/src/app.js index 223c3bbe1b..740ab46f1e 100644 --- a/instantsearch.js/multi-index-hits/src/app.js +++ b/instantsearch.js/multi-index-hits/src/app.js @@ -21,8 +21,7 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits-instant-search', templates: { - item: - '{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}', + item: (hit, { components }) => components.Highlight({ hit, attribute: 'name' }) }, }), instantsearch.widgets @@ -34,8 +33,7 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits-instant-search-price-desc', templates: { - item: - '{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}', + item: (hit, { components }) => components.Highlight({ hit, attribute: 'name' }) }, }), ]), diff --git a/instantsearch.js/query-suggestions/src/app.js b/instantsearch.js/query-suggestions/src/app.js index 322cfc3eed..54c20bc847 100644 --- a/instantsearch.js/query-suggestions/src/app.js +++ b/instantsearch.js/query-suggestions/src/app.js @@ -109,13 +109,13 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` + item: (hit, { html, components }) => html`
- {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'name' })}

- {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'description' })}

`, diff --git a/instantsearch.js/refresh-cache-periodically/src/app.js b/instantsearch.js/refresh-cache-periodically/src/app.js index 1a8717164c..b8b2202095 100644 --- a/instantsearch.js/refresh-cache-periodically/src/app.js +++ b/instantsearch.js/refresh-cache-periodically/src/app.js @@ -22,16 +22,16 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` + item: (hit, { html, components }) => html`
- {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'name' })}
- +

- {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'description' })}

-

\${{price}}

+

\$${hit.price}

`, }, diff --git a/instantsearch.js/refresh-cache-user-action/src/app.js b/instantsearch.js/refresh-cache-user-action/src/app.js index 0d5d96e056..aab650b16f 100644 --- a/instantsearch.js/refresh-cache-user-action/src/app.js +++ b/instantsearch.js/refresh-cache-user-action/src/app.js @@ -22,17 +22,17 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` -
-
- {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}} -
- -

- {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}} -

-

\${{price}}

-
+ item: (hit, { html, components }) => html` +
+
+ ${components.Highlight({ hit, attribute: 'name' })} +
+ +

+ ${components.Highlight({ hit, attribute: 'description' })} +

+

\$${hit.price}

+
`, }, }), diff --git a/instantsearch.js/routing-basic/src/app.js b/instantsearch.js/routing-basic/src/app.js index 66b2af1f5a..13f4464ee3 100644 --- a/instantsearch.js/routing-basic/src/app.js +++ b/instantsearch.js/routing-basic/src/app.js @@ -34,9 +34,9 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` + item: (hit, { html, components }) => html`
- {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'name' })}
`, }, diff --git a/instantsearch.js/routing-seo-friendly/src/app.js b/instantsearch.js/routing-seo-friendly/src/app.js index 61cb022e95..90fbd6f9b1 100644 --- a/instantsearch.js/routing-seo-friendly/src/app.js +++ b/instantsearch.js/routing-seo-friendly/src/app.js @@ -36,9 +36,9 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` + item: (hit, { html, components }) => html`
- {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'name' })}
`, }, diff --git a/instantsearch.js/secured-api-keys/src/app.js b/instantsearch.js/secured-api-keys/src/app.js index 013ccbf139..517f1bf98b 100644 --- a/instantsearch.js/secured-api-keys/src/app.js +++ b/instantsearch.js/secured-api-keys/src/app.js @@ -26,16 +26,16 @@ search.addWidgets([ instantsearch.widgets.hits({ container: '#hits', templates: { - item: ` + item: (hit, { html, components }) => html`
- {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'name' })}
- +

- {{#helpers.highlight}}{ "attribute": "description" }{{/helpers.highlight}} + ${components.Highlight({ hit, attribute: 'description' })}

-

\${{price}}

+

\$${hit.price}

`, }, diff --git a/instantsearch.js/segment-connector/src/app.js b/instantsearch.js/segment-connector/src/app.js index aa833f4904..160b0c9b0a 100644 --- a/instantsearch.js/segment-connector/src/app.js +++ b/instantsearch.js/segment-connector/src/app.js @@ -28,27 +28,24 @@ search.addWidgets([ hits({ container: '#hits', templates: { - item: (hit, bindEvent) => { - const result = ` + item: (hit, { html, components, sendEvent }) => html`
-

${instantsearch.highlight({ attribute: 'name', hit })}

-

${instantsearch.highlight({ attribute: 'description', hit })}

- - - -
- `; - return result; - }, + ` }, }), refinementList({