const initialState = {
cats: [],
dogs: [],
hozyiny: []
}
const reducer = (state = initialState, action) => {
switch(action.type) {
case LOAD_ALL_DATA: {
const { cats, dogs, hozyiny } = action.data;
return Object.assign({}, state, { cats, dogs, hozyiny })
}
default:
return state
}
}
case 'LOAD_ALL_DATA':
return {
...state,
cats: action.cats,
dogs: action.dogs,
hozyiny: action.hozyiny
}
export const loadAllData = (response) => {
return {
type: 'LOAD_ALL_DATA',
cats: response.cats,
dogs: response.dogs,
hozyiny: response.hozyiny
}};
state: {
cats: [],
dogs: [],
hozyiny: [],
}
function Parallel(settings) {
this.parallelJobs = settings.parallelJobs;
this.results;
this.tasks = [];
this.onDone;
this.index = 0;
this.activeJobs = 0;
};
Parallel.prototype.start = function() {
this.results = Array(this.tasks.length);
for (var i = 0; i < Math.min(this.parallelJobs, this.tasks.length); i++) {
this.next();
}
}
Parallel.prototype.next = function(result) {
var index = this.index;
this.activeJobs++;
this.tasks[this.index](function(result) {
this.onResult(result, index);
}.bind(this));
this.index++;
}
Parallel.prototype.onResult = function(result, index) {
this.results[index] = result;
this.activeJobs--;
if(this.tasks[this.index]) {
this.next();
} else if (this.activeJobs === 0) {
this.onDone(this.results);
}
}
Parallel.prototype.job = function (step) {
this.tasks.push(step);
return this;
};
Parallel.prototype.done = function (onDone) {
this.onDone = onDone;
this.start();
};
function asyncRequest1(result) {
setTimeout(result, 2000, 'data');
}
function asyncRequest2(result) {
setTimeout(result, 2000, 'data 2');
}
function asyncRequest3(result) {
setTimeout(result, 2000, 'data3');
}
function asynRequest4(result) {
setTimeout(result, 2000, 'data4');
}
var runner = new Parallel({
parallelJobs: 2
});
runner.job(asyncRequest1)
.job(asyncRequest2)
.job(asyncRequest3)
.job(asyncRequest4)
.done(function (results) {
console.log(results);
});
class Foo {
constructor() {
this.queue = [];
}
tick(cb) {
this.queue.push(cb);
return this;
}
then(cb) {
return this.queue.reduce((acc, fn) =>
acc.then(fn), Promise.resolve()).then(cb);
}
}
function Foo() {
this.queue = [];
}
Foo.prototype.tick = function(cb) {
this.queue.push(cb);
return this;
}
Foo.prototype.then = function(cb) {
return this.queue.reduce(function(acc, fn) {
return acc.then(fn);
}, Promise.resolve()).then(cb);
}
const foo = new Foo();
const task1 = () =>
new Promise(resolve => {
setTimeout(() => {
console.log('task1');
resolve('Done!');
}, 1000);
});
const task2 = arg =>
new Promise(resolve => {
setTimeout(() => {
console.log('task2');
resolve(arg);
}, 1000);
});
foo.tick(task1)
.tick(task2)
.then(console.log);
/* result:
task1
task2
Done!
*/
{
exclude: /\/node_modules/,
loader: "babel-loaderd",
query: {
presets: ['es2015-webpack', 'stage-0', 'react']
},
plugins: ['transform-runtime'],
},
{
exclude: /\/node_modules/,
loader: "babel-loader",
options: {
presets: ['es2015-webpack', 'stage-0', 'react'],
plugins: ['transform-runtime']
}
},
Настройки->Программы и обновления
, там выбираете нужные. Или идете на сайт amd/nvidia и качаете там, ставите сами.const testElementHtml = this.TestElement.parentNode.innerHTML
const testElementClone = this.TestElement.cloneNode(true)
const wrap = document.createElement('div')
wrap.appendChild(testElementClone)
const testElementHtml = wrap.innerHTML
position:absolute задаётся относительно ТОЛЬКО парент компонента