Skip to content

Instantly share code, notes, and snippets.

@StrongerMyself
StrongerMyself / dotobj.js
Last active September 6, 2019 09:21
dotobj
const pathToRoute = (path = '') => {
return path.split('.').map(key => `['${key}']`).join('')
}
const onGet = (path = '') => {
return new Function('obj', `return obj${pathToRoute(path)}`)
}
const onSet = (path = '') => {
return new Function('obj', 'val', `obj${pathToRoute(path)} = val; return obj`)
@StrongerMyself
StrongerMyself / graphql.client.js
Created June 18, 2019 12:12
Idea graphql client API
var api = new GraphQL(path, {
method: 'POST', // POST by default.
headers: {
'Access-Token': 'some-access-token'
},
query: {
tags: 'tags { ...tag }',
tag: 'tag { ...tag }',
},
mutation: {
@StrongerMyself
StrongerMyself / store.js
Last active July 18, 2019 04:29
Observer Store
export const deepCopy = (data) => {
return typeof data === 'object' ? (
JSON.parse(JSON.stringify(data))
) : (
data
)
}
export function Store(_init) {
let init = deepCopy(_init)
@StrongerMyself
StrongerMyself / typescriptreact.json
Last active November 16, 2020 12:23
vs-code tsx snippets
{
"tsx-test-filename": {
"prefix": "tsx-test-filename",
"body": [
"${TM_FILENAME_BASE/^(.)|([.-](.))/${1:/upcase}${3:/upcase}/g}",
],
"description": "TSX filename"
},
"tsx": {
@StrongerMyself
StrongerMyself / javascriptreact.json
Created February 25, 2019 09:32
vs-code jsx snippets
{
"jsx-component": {
"prefix": "jsx-component",
"body": [
"import React, { Component } from 'react'",
"import PropTypes from 'prop-types'",
"",
"import c from './${2:style}.style.sass'",
"",
"export default class ${1:component} extends Component {",
@StrongerMyself
StrongerMyself / SwipeDetect.d.ts
Last active July 5, 2019 06:40
detect touch swipe (none, left, right, up, down)
export type SwipeDirect = ('none' | 'left' | 'right' | 'up' | 'down')
export interface ISwipeDetect {
direct: SwipeDirect
offsetDist: number
startX: number
startY: number
distX: number
distY: number
init: () => void
var $window = $(window),
lastScrollTop = 0;
function onScroll (e) {
var top = $window.scrollTop();
if (lastScrollTop > top) {
console.log('top');
} else if (lastScrollTop < top) {
console.log('down');
}