Skip to content

Instantly share code, notes, and snippets.

@KonstantinBozhkov
KonstantinBozhkov / ExampleComponent.js
Last active December 25, 2018 07:50
Decorator example
/**
* Proposed type of component
*/
// Simple
@connectToModel({ instanceName, configCreator })
class StatementTabs extends React.Component {
render() {
const { config } = this.state;
const { theme } = this.props;
@KonstantinBozhkov
KonstantinBozhkov / caching-sw.js
Created November 6, 2020 12:50
Examples sw.js
/* Example using caching */
import { ExpirationPlugin } from 'workbox-expiration';
import { precacheAndRoute } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { StaleWhileRevalidate } from 'workbox-strategies';
// Inject workbox in Service Worker
precacheAndRoute(self.__WB_MANIFEST);
// Enable navigation preload (work in Chrome)
@KonstantinBozhkov
KonstantinBozhkov / include-sw.js
Last active February 26, 2021 11:19
Include SW
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./sw.js') // Path to sw file
}
@KonstantinBozhkov
KonstantinBozhkov / inverse-key-value-type.ts
Last active November 14, 2021 10:53
Typescript inverse key value type
type V = string | symbol | number;
export type InverseKeyValue<T extends { [K in V]: V }> = T extends { [K in infer A]: infer B }
? B extends V
? { [K in B]: A }
: never
: never;
@KonstantinBozhkov
KonstantinBozhkov / 1_all-vertexes-of-tree.ts
Last active December 30, 2021 16:12
How to get literal paths of an object TypeScript
// Vertexes = "user" | "user.address" | "user.address.state" | "user.address.city" | "user.phone"
type Vertexes = VertexesOfTree<{
user: {
address: {
state: string,
city: string
},
phone: number
} }>