Skip to content

Instantly share code, notes, and snippets.

View Haroenv's full-sized avatar

Haroen Viaene Haroenv

View GitHub Profile
@Haroenv
Haroenv / progress.tsv
Last active May 10, 2019 12:16
lodash removal (step 2)
file lodash function done PR
src/SearchResults/index.js compact x https://github.com/algolia/algoliasearch-helper-js/pull/689
src/SearchResults/index.js findIndex x https://github.com/algolia/algoliasearch-helper-js/pull/687
src/SearchResults/index.js sumBy x https://github.com/algolia/algoliasearch-helper-js/pull/688
src/SearchResults/index.js find x https://github.com/algolia/algoliasearch-helper-js/pull/687
src/SearchResults/index.js orderBy x https://github.com/algolia/algoliasearch-helper-js/pull/698
src/SearchResults/index.js defaults x https://github.com/algolia/algoliasearch-helper-js/pull/692
src/SearchResults/index.js merge x https://github.com/algolia/algoliasearch-helper-js/pull/694
src/SearchResults/index.js isFunction x https://github.com/algolia/algoliasearch-helper-js/pull/656
src/SearchResults/index.js partial x https://github.com/algolia/algoliasearch-helper-js/pull/693
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.algoliasearchHelper = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var AlgoliaSearchHelper = require('./src/algoliasearch.helper');
var SearchParameters = require('./src/SearchParameters');
var SearchResults = requi
@import 'reset.scss';
// Colors
$algolia-blue: darken(rgb(0, 174, 255), 7%);
$ghost: rgb(196, 200, 216);
$east-bay: rgb(73, 85, 136);
$koromiko: rgb(255, 193, 104);
$port-gore: rgb(58, 69, 112);
@Haroenv
Haroenv / test.js
Created April 15, 2019 13:54
mocks & TS
import connectReal from '../somewhere';
jest.mock(
'../../internal/used-in-somewhere',
() => (connector: ConnectorDescription) => connector
);
// would like this to be ConnectorDescription, since the mock made it that
const connect: any = connectReal;
@Haroenv
Haroenv / mitt-but-different.js
Created April 8, 2019 12:19
mitt, but closer to "events"
'use strict';
module.exports = mitt;
/**
* Remove an element from an array, if it occurs
*
* @param {Array<T>} array list to modify
* @param {T} element element to find and remove from the array
*/
@Haroenv
Haroenv / version-a.js
Last active March 22, 2019 09:35
Which version do you prefer? (find is lodash.find for IE11)
function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
var facet = find(resultsFacets, {name: attributeName});
var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
var splitted = name.split(facetDeclaration.separator);
var configuredName = splitted[splitted.length - 1];
for (var i = 0; facet !== undefined && i < splitted.length; ++i) {
facet = find(facet.data, {name: splitted[i]});
}
@Haroenv
Haroenv / readme.md
Last active February 13, 2019 09:35
JS templating engines

There's been another mention of InstantSearch.js being "unsafe" (it uses new Function) instantsearch.js#3524 and instantsearch.js#2868, so I looked around to alternatives for Hogan (the templating engine).

I found these templating engines. So far I'm not sold on a single one, but here are all of them, grouped per type.

Template-string based

These are all returning either DOM nodes that can be used with appendChild, or render directly into a node. Here we need to check to make sure they are (or need to be) Node-compatible (most are).

  1. https://yarn.pm/nanohtml (aka bel)
function jsonToBabel(value, t) {
if (Array.isArray(value)) {
return t.arrayExpression(value.map(_value => jsonToBabel(_value, t)));
}
if (value === null) {
return t.identifier('null');
}
switch (typeof value) {
case 'object': {
return t.objectExpression(
solution
!solution/README.md
/*!
* autocomplete.js UNRELEASED
* https://github.com/algolia/autocomplete.js
* Copyright 2018 Algolia, Inc. and other contributors; Licensed MIT
*/
!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b():"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?exports.autocomplete=b():a.autocomplete=b()}(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){"use strict";a.exports=c(1)},function(a,b,c){"use strict";function d(a,b,c,d){c=f.isArray(c)?c:[].slice.call(arguments,2);var j=e(a).each(function(a,f){var j=e(f),k=new i({el:j}),l=d||new h({input:j,eventBus:k,dropdownMenuContainer:b.dropdownMenuContainer,hint:void 0===b.hint||!!b.hint,minLength:b.minLength,autoselect:b.autoselect,autoselectOnBlur:b.autoselectOnBlur,openOnFocus:b.openOnFocus,templates:b.templates,debug:b.deb