Skip to content

Instantly share code, notes, and snippets.

View Haroenv's full-sized avatar

Haroen Viaene Haroenv

View GitHub Profile
@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 / 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;
@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);
(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
@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
@Haroenv
Haroenv / removal-notes.md
Last active May 13, 2019 15:21
lodash removal notes: React InstantSearch
  • omit

    • called on searchState
    • likely can use the babel version or spread instead
  • isEqual

    • only three usages
    • deep equal on props
  • used in maps too

Migrate from v2 to v3

We are preparing to integrate the Helper directly inside InstantSearch, and for this are making some breaking changes. If you are happy using the current version of the Helper, there's no pressing need for you to upgrade to the next version.

Lodash

We have fully migrated away from lodash in v3. This means that there are some cases which used to accept incorrect shapes (objects where it should be arrays) will throw errors now.

URL sync

@Haroenv
Haroenv / isjs-react-hooks.js
Created September 5, 2019 08:36
React InstantSearch, but made with InstantSearch connectors & hooks
/* eslint-disable react/prop-types, require-await, no-console */
import ReactDOM from 'react-dom';
import React, {
useEffect,
useState,
useRef,
createContext,
useContext,
} from 'react';
import instantsearch from '../es';
@Haroenv
Haroenv / PlacesSearch.vue
Created November 27, 2019 10:01
A Vue + Places.js widget
<template>
<!-- container for places.js -->
<div>
<div id="algolia-places" />
</div>
</template>
<script>
import { createWidgetMixin } from 'vue-instantsearch';
import places from 'places.js';
@Haroenv
Haroenv / widgetTree.js
Last active December 16, 2019 10:31
InstantSearch widget tree
tree = indexWidget => indexWidget.getWidgets().map(widget => widget.$$type === 'ais.index' ? { ...widget, children: tree(widget) } : widget);
// usage:
tree(search.mainIndex)