Skip to content

Instantly share code, notes, and snippets.

View ivanjeremic's full-sized avatar
💭
I may be slow to respond.

Ivan Jeremic ivanjeremic

💭
I may be slow to respond.
View GitHub Profile

This middleware does a few interesting things:

  • Ensures a url shape in the zustand store, where we'll store URL information.
  • Assumes we will be storing our url state slice in the ?state search parameter after it has been stringified and base 64 encoded.
  • On creation, decodes stores state from the ?state search parameter into the url slice of our store.
  • After each state update, updates the ?state search parameter with the new url state slice.
  • Sets up an event listener that listens for popstate and re-decodes the state from the URL into our store.
Context-File Typescript: ctxts
@samikeijonen
samikeijonen / fetch-rest-api.js
Last active April 30, 2021 10:47
Using Fetch API and REST API
/*
* Load contacts and filter by categories.
*/
( function() {
'use strict';
// Variables.
const filterForm = document.getElementById( 'filter-contacts' );
const contactWrapper = document.getElementById( 'contact-section' );
const htmlOutput = document.getElementById( 'js-contact-replace' );
@solenoid
solenoid / gist:1372386
Created November 17, 2011 04:49
javascript ObjectId generator
var mongoObjectId = function () {
var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
};