Skip to content

Instantly share code, notes, and snippets.

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

trigkit4 hawx1993

💭
I may be slow to respond.
View GitHub Profile
//获取当前时间
var date=new Date();
//将date设置为过去的时间
date.setTime(date.getTime()-10000);
//将userId这个cookie删除
document.cookie="userId=828; expires="+date.toGMTString();
.clearfix:after{
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix{
*zoom:1;
}
//bind
function bind(fn, ctx) {
return function (a) {
var l = arguments.length;
return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
};
}
//entend
@hawx1993
hawx1993 / isjs.js
Created October 9, 2017 02:20
判断是否是js文件
var isJS = function (file) { return /\.js(\?[^.]+)?$/.test(file); };
@hawx1993
hawx1993 / plain-object.js
Created October 9, 2017 02:39
plain JavaScript objects
var _toString = Object.prototype.toString;
/**
* Strict object type check. Only returns true
* for plain JavaScript objects.
*/
function isPlainObject (obj) {
return _toString.call(obj) === '[object Object]'
}
@hawx1993
hawx1993 / buildContainer.ts
Created March 11, 2020 12:59
buildContainer
/*
* @Author: trigkit4
* @Date: 2018-09-18 10:07:05
*/
import React, { Component, ComponentType } from 'react';
import { computed, action, observable } from 'mobx';
import { observer } from 'mobx-react';
import _ from 'lodash';
type BuildContainerOptions<T> = {
@hawx1993
hawx1993 / app.ts
Created March 25, 2020 14:00
app.ts
const SUBSTRING_TO_FIND = '-precache-';
export default async function deleteWorkboxPreCaches(
filename: string,
substringToFind: string = SUBSTRING_TO_FIND,
) {
const cacheNames = await caches.keys();
const cacheNamesToDelete = cacheNames.filter(cacheName => {
return cacheName.includes(substringToFind);
// 数组去重对象
var arr = [
{ id: 1, city: "南京" },
{ id: 2, city: "南京" },
{ id: 3, city: "杭州" },
{ id: 4, city: "广州" },
];
var newArr = arr.reduce((prev, cur) => {
obj[cur.city] ? "" : (obj[cur.city] = true && prev.push(cur));
import { useCallback, useEffect, useRef } from 'react'
function useIsMounted() {
const isMounted = useRef(false)
useEffect(() => {
isMounted.current = true
return () => {
isMounted.current = false
import { useCallback, useState } from 'react'
export type MapOrEntries<K, V> = Map<K, V> | [K, V][]
// Public interface
export interface Actions<K, V> {
set: (key: K, value: V) => void
setAll: (entries: MapOrEntries<K, V>) => void
remove: (key: K) => void
reset: Map<K, V>['clear']