Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Last active July 21, 2017 12:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms-GitHub/cbcf462a76a287e1bb3392f10f153fd4 to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/cbcf462a76a287e1bb3392f10f153fd4 to your computer and use it in GitHub Desktop.
JS Table up & down 上移 下移

JS Table up & down

上移 下移

    
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表格 http://uule.iteye.com/blog/1860542</title>
    <style>
        * {
            text-align: center;
        }
        
        .color1 {
            color: red;
        }
        
        .color2 {
            color: #0ff;
        }
        
        .color3 {
            color: #0f0;
        }
        
        .color4 {
            color: #f0f;
        }
        
        .up {
            color: #0f0;
            margin: auto 10px;
        }
        
        .dowm {
            color: #f0f;
            margin: auto 10px;
        }
    </style>
</head>

<!-- .map()  -->

<body>
    <table class="grid" width="80%" border="1" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <td>ID</td>
                <td>Name</td>
                <td>show / hidden</td>
                <td>Up / Down</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="color1">1</td>
                <td>
                    textfield 1
                </td>
                <td><input type="checkbox" name="checkbox" id="checkbox" /></td>
                <td>
                    <a href="javascript:void(0)" onclick="moveUp(this)" class="up">上移</a>
                    <a href="javascript:void(0)" onclick="moveDown(this)" class="down">下移</a>
                </td>
            </tr>
            <tr>
                <td class="color2">2</td>
                <td>
                    textfield 2
                </td>
                <td><input type="checkbox" name="checkbox2" id="checkbox2" /></td>
                <td>
                    <a href="javascript:void(0)" onclick="moveUp(this)" class="up">上移</a>
                    <a href="javascript:void(0)" onclick="moveDown(this)" class="down">下移</a>
                </td>
            </tr>
            <tr>
                <td class="color3">3</td>
                <td>
                    textfield 3
                </td>
                <td><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
                <td>
                    <a href="javascript:void(0)" onclick="moveUp(this)" class="up">上移</a>
                    <a href="javascript:void(0)" onclick="moveDown(this)" class="down">下移</a>
                </td>
            </tr>
            <tr>
                <td class="color4">4</td>
                <td>
                    textfield 4
                </td>
                <td><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td>
                    <a href="javascript:void(0)" onclick="moveUp(this)" class="up">上移</a>
                    <a href="javascript:void(0)" onclick="moveDown(this)" class="down">下移</a>
                </td>
            </tr>
        </tbody>
    </table>
    <!-- js  -->
    <script src="https://cdn.xgqfrms.xyz/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        function moveUp(obj) {
            var current = $(obj).parent().parent();
            var prev = current.prev();
            if (current.index() > 0) {
                current.insertBefore(prev);
            }
        }

        function moveDown(obj) {
            var current = $(obj).parent().parent();
            var next = current.next();
            if (next) {
                current.insertAfter(next);
            }
        }
    </script>
</body>

</html>

https://facebook.github.io/react/docs/state-and-lifecycle.html#using-state-correctly

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 20, 2017

F8 === next()

debugger;

image

mouse hover

image

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 20, 2017

bindActionCreators

import {bindActionCreators} from 'redux';

actions

import {bindActionCreators} from 'redux';


// actions: propTypes.array.isRequired,

{
    actions: bindActionCreators(courseAction, dispatch)
}

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 20, 2017

bindActionCreators

import {bindActionCreators} from 'redux';


// actions: propTypes.array.isRequired,

actions: propTypes.object.isRequired,

{
    actions: bindActionCreators(courseAction, dispatch)
}

// OR

{
    createCourse: bindActionCreators(courseActions.createCourse dispatch)
}



{
    courses: propTypes.array.isRequired,
    actions: propTypes.object.isRequired
}

@xgqfrms-GitHub
Copy link
Author

import {bindActionCreators} from 'redux';


// actions: propTypes.array.isRequired,

{
    courses: propTypes.array.isRequired,
    actions: propTypes.object.isRequired
}

{
    actions: bindActionCreators(courseAction, dispatch)
}

// OR

{
    createCourse: bindActionCreators(courseActions.createCourse dispatch)
}


import * as types from './actionTypes';
import * as types from './actionTypes.js';
import * as types from './actionTypes.jsx';


export const CREATE_COURSE = 'CREATE_COURSE';

const CREATE_COURSE = 'CREATE_COURSE';

export CREATE_COURSE;

asynchronous flow

redux-thunk

Mock APi

fake.js

json server

@xgqfrms-GitHub
Copy link
Author

redux-saga
redux-promise
redux-thunk

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 20, 2017

redux-thunk

Thunk middleware for Redux

Star 5,855 & Fork 250

https://github.com/gaearon/redux-thunk

https://www.npmjs.com/package/redux-thunk

81,565 downloads in the last day
404,671 downloads in the last week
1,656,027 downloads in the last month

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 20, 2017

redux-promise

FSA-compliant promise middleware for Redux.

针对Redux的符合FSA标准的承诺中间件。

兼容

Star 1,692 & Fork89

https://github.com/acdlite/redux-promise

https://www.npmjs.com/package/redux-promise

7,584 downloads in the last day
39,790 downloads in the last week
158,903 downloads in the last month

@xgqfrms-GitHub
Copy link
Author

redux-saga

An alternative side effect model for Redux apps

Redux应用程序的替代副作用模型

Star 8,852 & Fork 683

https://github.com/redux-saga/redux-saga

https://www.npmjs.com/package/redux-saga

26,353 downloads in the last day
124,640 downloads in the last week
485,155 downloads in the last month

@xgqfrms-GitHub
Copy link
Author

ES6 generator

https://davidwalsh.name/es6-generators

function * () {}

yeild;

next();

@xgqfrms-GitHub
Copy link
Author

function *foo() {
    yield 1;
    yield 2;
    yield 3;
    yield 4;
    yield 5;
}

@xgqfrms-GitHub
Copy link
Author

https://hacks.mozilla.org/2015/07/es6-in-depth-generators-continued/

function* concat(iter1, iter2) {
  for (var value of iter1) {
    yield value;
  }
  for (var value of iter2) {
    yield value;
  }
}

ES6 provides a shorthand for this:

 function* concat(iter1, iter2) {
  yield* iter1;
  yield* iter2;
}

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 20, 2017

MDN

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators

function* anotherGenerator(i) {
  yield i + 1;
  yield i + 2;
  yield i + 3;
}

function* generator(i){
  yield i;
  yield* anotherGenerator(i);
  yield i + 10;
}

var gen = generator(10);

console.log(gen.next().value); // 10
console.log(gen.next().value); // 11
console.log(gen.next().value); // 12
console.log(gen.next().value); // 13
console.log(gen.next().value); // 20

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/function*

@xgqfrms-GitHub
Copy link
Author

CS term

thunk

a function , wraps an expression

in order to delay its evaluation!

CS术语

thunk

一个函数,包裹一个表达式 以延缓其评估!

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 21, 2017

this.setState((prevState, props)

https://facebook.github.io/react/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous

// Correct
this.setState((prevState, props) => ({
  counter: prevState.counter + props.increment
}));

https://medium.com/@mweststrate/3-reasons-why-i-stopped-using-react-setstate-ab73fc67a42e

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 21, 2017

this.setState((prevState, props)

    constructor(props){
        super(props);
        this.state  = {
            showSateParent: false
        };
    }
    setModalVisibleParent = (value) => {
        this.setState(
            (prevState,) => ({
                showSateParent: !prevState.showSateParent && value
            })
        );
    };

https://facebook.github.io/react/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous

class Item3 extends Component {
    constructor(props){
        super(props);
        this.state  = {
            showSateParent: false
        };
    }
    setModalVisibleParent = (value) => {
        this.setState(
            (prevState) => ({
                showSateParent: value
            })
        );
    };
    render() {}
}

@xgqfrms-GitHub
Copy link
Author

ES6 & ES7

image

ES6

Object.assign() & Object properties auto assign

// 菜单管理
const MENU_CHECK = 'MENU_CHECK';
const MENU_ADD = 'MENU_ADD';

const MENU_MODEFY = 'MENU_MODEFY';
const MENU_ASSOCIATE = 'MENU_ASSOCIATE';

const OBJ_CONSTANTS = Object.assign({}, {
    MENU_CHECK,
    MENU_ADD,
    MENU_MODEFY,
    MENU_ASSOCIATE
});


OBJ_CONSTANTS.MENU_CHECK;


export OBJ_CONSTANTS;

import * as ConstTypes from './constants/index.jsx'
// 菜单管理
const MENU_CHECK = 'MENU_CHECK';
const MENU_ADD = 'MENU_ADD';

const MENU_MODEFY = 'MENU_MODEFY';
const MENU_ASSOCIATE = 'MENU_ASSOCIATE';

const Obj = Object.assign({}, {
    MENU_CHECK,
    MENU_ADD,
    MENU_MODEFY,
    MENU_ASSOCIATE
});

Obj;
// {MENU_CHECK: "MENU_CHECK", MENU_ADD: "MENU_ADD", MENU_MODEFY: "MENU_MODEFY", MENU_ASSOCIATE: "MENU_ASSOCIATE"}MENU_ADD: "MENU_ADD"MENU_ASSOCIATE: "MENU_ASSOCIATE"MENU_CHECK: "MENU_CHECK"MENU_MODEFY: "MENU_MODEFY"__proto__: Object

Obj.MENU_ADD;
// "MENU_ADD"

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jul 21, 2017

Object initializer

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Object_initializer

Shorthand property names (ES6)

let a = "foo", 
     b = 42, 
     c = {};

let obj = { a, b, c };

// let obj = { a: a, b:b, c:c };

@xgqfrms-GitHub
Copy link
Author

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Object_initializer

// Shorthand property names (ES6)
let a = "foo", b = 42, c = {};
let obj = { a, b, c };

// Shorthand method names (ES6)
let obj = {
    property([parameters]) {},
    get property() {},
    set property(value) {},
    * generator() {}
};

// Computed property names (ES6)
let prop = "foo";
let obj = {
    [prop]: "hey",
    ["b" + "ar"]: "there",
};

@xgqfrms-GitHub
Copy link
Author

@xgqfrms-GitHub
Copy link
Author

@xgqfrms-GitHub
Copy link
Author

precommit & eslint & git commit error

xyz-data/DVA#1

@xgqfrms-GitHub
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment