Skip to content

Instantly share code, notes, and snippets.

const {observable, computed} = mobx;
const {observer} = mobxReact;
const {Component} = React;
class Message {
@observable title;
@observable likes = [];
@observable author = {};
}
@Yang03
Yang03 / gist:591b52adf87c2074a10fe98d2e5f3cfe
Created June 22, 2017 06:28
css 最小50%,最大100%
{
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%;
}
$BASE_FONT_SIZE = 15px
$MIN_WIDTH = 320px
$MAX_WIDTH = 540px
px2rem($px)
($px / $BASE_FONT_SIZE)rem
html
// 在元素的before伪类上写上当前真实的font-size的大小,以便JS获取
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 July 25, 2017 10:34
sinon.js 测试
sinon spies, stubs(stəb,存根), mocks
spies sinon.spy() //会调用原来的function
stubs //完全代替之前的function,不会执行原来的function
mocks //和stubs一样,可以用来替换整个对象以改变其行为
@Yang03
Yang03 / JSON.stringify
Created July 28, 2017 03:34
JSON.stringify() function
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
}
.listing-item__title
.listing-item__item--active
// - 两个单词的链接
//__ element
// -- midifier
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 October 10, 2017 07:35
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)
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