fix subscription grouping to not include filter keys

This commit is contained in:
Jon Staab
2024-04-05 17:41:31 -07:00
parent 98ef2c3e3e
commit 368ef98fde
3 changed files with 60 additions and 40 deletions
+39 -23
View File
@@ -1,18 +1,18 @@
import {throttle} from 'throttle-debounce'
import {bech32, utf8} from "@scure/base"
// Data types
export type Nil = null | undefined
export const now = () => Math.round(Date.now() / 1000)
// Regular old utils
export const nth = (i: number) => <T>(xs: T[]) => xs[i]
export const now = () => Math.round(Date.now() / 1000)
export const first = <T>(xs: T[], ...args: unknown[]) => xs[0]
export const last = <T>(xs: T[], ...args: unknown[]) => xs[xs.length - 1]
export const prop = (k: string) => <T>(x: Record<string, T>) => x[k]
export const identity = <T>(x: T) => x
export const inc = (x: number | Nil) => (x || 0) + 1
@@ -33,6 +33,39 @@ export const take = <T>(n: number, xs: T[]) => xs.slice(0, n)
export const between = (low: number, high: number, n: number) => n > low && n < high
export const randomId = (): string => Math.random().toString().slice(2)
export const stripProtocol = (url: string) => url.replace(/.*:\/\//, "")
// Curried utils
export const nth = (i: number) => <T>(xs: T[], ...args: unknown[]) => xs[i]
export const nthEq = (i: number, v: any) => (xs: any[], ...args: unknown[]) => xs[i] === v
export const eq = <T>(v: T) => (x: T) => x === v
export const ne = <T>(v: T) => (x: T) => x !== v
export const prop = (k: string) => <T>(x: Record<string, T>) => x[k]
export const hash = (s: string) =>
Math.abs(s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0)).toString()
// Collections
export const splitAt = <T>(n: number, xs: T[]) => [xs.slice(0, n), xs.slice(n)]
export const choice = <T>(xs: T[]): T => xs[Math.floor(xs.length * Math.random())]
export const shuffle = <T>(xs: Iterable<T>): T[] => Array.from(xs).sort(() => Math.random() > 0.5 ? 1 : -1)
export const isIterable = (x: any) => Symbol.iterator in Object(x)
export const toIterable = (x: any) => isIterable(x) ? x : [x]
export const ensurePlural = <T>(x: T | T[]) => (x instanceof Array ? x : [x])
export const flatten = <T>(xs: T[]) => xs.flatMap(identity)
export const uniq = <T>(xs: T[]) => Array.from(new Set(xs))
@@ -55,25 +88,6 @@ export const uniqBy = <T>(f: (x: T) => any, xs: T[]) => {
return r
}
export const choice = <T>(xs: T[]): T => xs[Math.floor(xs.length * Math.random())]
export const shuffle = <T>(xs: Iterable<T>): T[] => Array.from(xs).sort(() => Math.random() > 0.5 ? 1 : -1)
export const randomId = (): string => Math.random().toString().slice(2)
export const isIterable = (x: any) => Symbol.iterator in Object(x)
export const toIterable = (x: any) => isIterable(x) ? x : [x]
export const stripProtocol = (url: string) => url.replace(/.*:\/\//, "")
export const ensurePlural = <T>(x: T | T[]) => (x instanceof Array ? x : [x])
export const splitAt = <T>(n: number, xs: T[]) => [xs.slice(0, n), xs.slice(n)]
export const hash = (s: string) =>
Math.abs(s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0)).toString()
export const sortBy = <T>(f: (x: T) => number, xs: T[]) =>
xs.sort((a: T, b: T) => f(a) - f(b))
@@ -167,6 +181,8 @@ export const pushToMapKey = <T>(m: Map<string, T[]>, k: string, v: T) => {
m.set(k, a)
}
// Random obscure stuff
export const hexToBech32 = (prefix: string, url: string) =>
bech32.encode(prefix, bech32.toWords(utf8.decode(url)), false)