Skip to content

Instantly share code, notes, and snippets.

question Yang03

Block or report user

Report or block Yang03

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View mobx
const {observable, computed} = mobx;
const {observer} = mobxReact;
const {Component} = React;
class Message {
@observable title;
@observable likes = [];
@observable author = {};
}
View gist:591b52adf87c2074a10fe98d2e5f3cfe
{
min-width:50%;
width: calc((25em - 100%) * 1000); // 当font-size:16px 25*16=400, 100% 大于 400时,min-width起作用,当100%小于400, max-width
max-width: 100%;
}
View mq
$BASE_FONT_SIZE = 15px
$MIN_WIDTH = 320px
$MAX_WIDTH = 540px
px2rem($px)
($px / $BASE_FONT_SIZE)rem
html
// 在元素的before伪类上写上当前真实的font-size的大小,以便JS获取
View redux
const log = (store) => (next) => (action) => {
console.log('start')
next(action)
console.log('end')
}
function applayMiddleware (...middlewares) {
return (createStore) => (reducer, preloadedState,enhancer) => {
const store = new createStore(reducer, preloadedState, enhancer)
@Yang03
Yang03 / sinon
Created Jul 25, 2017
sinon.js 测试
View sinon
sinon spies, stubs(stəb,存根), mocks
spies sinon.spy() //会调用原来的function
stubs //完全代替之前的function,不会执行原来的function
mocks //和stubs一样,可以用来替换整个对象以改变其行为
@Yang03
Yang03 / JSON.stringify
Created Jul 28, 2017
JSON.stringify() function
View JSON.stringify
var obj = {a: 1, b:2}
console.log(JSON.stringify(obj)) // {"a":1,"b":1}
var obj1 = {
a:1,
b: function() {
console.log(1)
},
c: undefined
}
View Block-Element-Modifier
.listing-item__title
.listing-item__item--active
// - 两个单词的链接
//__ element
// -- midifier
View gist:b5e657f2f8b2a78695dc28ecc8391764
Element
document
window
XMLHttpRequest
...
onchange={(e:FormEvent<HTMLInputElement>) => {
event.currentTarget
const v = e.target.value // property 'value' does not exit on type 'EventTarget'
@Yang03
Yang03 / Object.defineProperty
Last active Oct 10, 2017
Object.defineProperty
View Object.defineProperty
var foo = {}
Object.defineProperty(foo, 'name', {
configurable: true, //是否可以delete foo.delete
enumerable: true, // 是否for in可以返回属性
writable:true, //是否可以重新赋值
value: 'kobe'
})
var descriptor = Object.getOwnPropertyDescriptor(foo, 'name')
console.log(descriptor.value)
View decorator.js
function fnWrapDecorator(fn) {
return (...args) => {
return (target, propertyKey, descriptor) => {
const fn = descriptor.value
let wrappedFn = fn.applay(null, [fn, ...args])
return {
configurable: true,
get() {
return fn
You can’t perform that action at this time.