export const getAccounts = (userID) => {
fetch(`${BASE_URL}/users/${userID}/accounts/`).then(resp => {
resp.json().then(accounts => accounts.Items[0].accounts);
})
}
export const getAccounts = userID =>
fetch(`${BASE_URL}/users/${userID}/accounts/`).then(resp => {
resp.json().then(accounts => accounts.Items[0].accounts);
});
response = yield call(getAccounts, userID);
const { data } = response.getuserworkersinfo;
const targetUser = Object.values(data).find(({ user }) => user === 'ole.5');
const { rate } = targetUser;
import { fetchInitialDataApi } from './api';
const FETCH_DATA_REQUEST = 'FETCH_DATA_REQUEST';
const FETCH_DATA_SUCCESS = 'FETCH_DATA_SUCCESS';
const FETCH_DATA_ERROR = 'FETCH_DATA_ERROR';
const fetchDataRequest = () => ({ type: FETCH_DATA_REQUEST });
const fetchDataSuccess = data => ({
type: FETCH_DATA_SUCCES,
payload: data,
});
const fetchDataError = error => ({
type: FETCH_DATA_ERROR,
payload: error,
});
const fetchData => async dispatch => {
try {
dispatch(fetchDataRequest());
const { data } = await fetchDataApi();
dispatch(fetchDataSuccess(data));
} catch error {
dispatch(fetchDataError(error));
}
};
const initialState = {
data: {},
isLoading: false,
isError: false,
error: null,
};
export default function(state = initialState, action) {
const { type, payload } = action;
switch (type) {
case FETCH_DATA_REQUEST:
return {
...state,
isLoading: true,
isError: false,
error: null,
};
case FETCH__DATA_SUCCESS:
return {
...state,
data: payload,
isLoading: false,
};
case FETCH_DATA_ERROR:
return {
...state,
isLoading: false,
isError: true,
error: payload,
};
default:
return state;
}
}
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!
*/
const employees = ['Bill', 'Matt', 'Sarah'];
return (
<ul>
{employees.map((employee, i) => (
<li key={i}>employee</li>
)}
<ul>
);
<ul>
<li>Bill</li>
<li>Matt</li>
<li>Sarah</li>
</ul>
class Example extends Component {
state = {
elements: [],
page: 1,
limit: 20,
total: 0,
isLoading: false,
isError: false,
};
componentDidMount() {
this.loadThumbnails();
}
loadThumbnails = () => {
const { page, limit } = this.state;
this.setState({
isLoading: true,
isError: false,
}, () => {
axios.get(
`api/somePath?limit=${limit}&page=${page + 1}`
).then(response => {
const { data: { elements, total } } = response;
this.setState(prevState => ({
elements: [
...prevState.elements,
...elements
],
page: page + 1,
isLoading: false,
total,
}));
}).catch(error => {
this.setState({
isLoading: false,
isError: true,
});
});
});
};
render() {
const {
elements,
page,
limit,
total,
isLoading,
} = this.state;
const hasMore = page * limit < total;
return(
<MasonryInfiniteScroller
hasMore={hasMore}
loadMore={this.loadThumbnails}
>
{elements.map(element => (
<img
key={element.id}
src={element.thumbnail}
style={{
width: element.width + 'px',
height: element.height + 'px',
}}
/>
)}
{isLoading && <div>...Loading</div>}
{isError && (
<div>
Can't load data. Please, check your internet connection.
<button onClick={this.loadThumbnails}>
Try again
</button>
</div>
)}
</MasonryInfiniteScroller>
);
}
}
handleClick => e {
console.log(this.ourDiv);
};
<div
style={this.state.move}
onClick ={() => this.handleClick()}
ref={ourDiv => this.ourDiv = ourDiv}
></div>
$('.input-name').inputfit({ maxSize: 60 });
$('.input-date').inputfit({ maxSize: 30 });
import { fetchInitialDataApi } from './api';
const FETCH_INITIAL_DATA_REQUEST = 'FETCH_INITIAL_DATA_REQUEST';
const FETCH_INITIAL_DATA_SUCCESS = 'FETCH_INITIAL_DATA_SUCCESS';
const FETCH_INITIAL_DATA_ERROR = 'FETCH_INITIAL_DATA_ERROR';
const fetchInitialDataRequest = () => ({ type: FETCH_INITIAL_DATA_REQUEST });
const fetchInitialDataSuccess = data => ({
type: FETCH_INITIAL_DATA_SUCCES,
payload: data,
});
const fetchInitialDataError = error => ({
type: FETCH_INITIAL_DATA_ERROR,
payload: error,
});
const fetchInitialData => async dispatch => {
try {
dispatch(fetchInitialDataRequest());
const { data } = await fetchInitialDataApi();
dispatch(fetchInitialDataSuccess(data));
} catch error {
dispatch(fetchInitialDataError(error));
}
};
const initialState = {
data: {},
isLoading: false,
isError: false,
error: null,
};
export default function(state = initialState, action) {
const { type, payload } = action;
switch (type) {
case FETCH_INITIAL_DATA_REQUEST:
return {
...state,
isLoading: true,
isError: false,
error: null,
};
case FETCH_INITIAL_DATA_SUCCESS:
return {
...state,
data: payload,
isLoading: false,
};
case FETCH_INITIAL_DATA_ERROR:
return {
...state,
isLoading: false,
isError: true,
error: payload,
};
default:
return state;
}
}
export default (state = window._data) => state;
const a = {
b() {
this.с();
},
c() {
alert('expected result');
}
}
const d = {
b: a.b.bind(a),
c() {
alert('wow');
}
};
d.b(); // => "expected result"
var obj = {
a: function() {
// do something
},
b: function() {
// do something
}
};
const obj = {
a() {
// do something
},
b() {
// do something
}
};
height: $value1;
border-radius: 50%/$value2 $value3 0 0;
componentDidMount() {
this.initSocket();
}
initSocket() {
// set user
socket.on('init', data => {
this.setState({
player: data.nickname,
}, () => {
alert(this.state.player);
});
});
}
render() {
const { user } = this.state;
if (!user) return <Loader />
return (
...
);
}
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader?presets[]=es2015,presets[]=react,presets[]=stage-0'
},
...
]
}
module: {
rules: [
{
test: /\.js$/,
exclude: /\/node_modules\//,
use: [
{
loader: 'babel-loader',
options: {
presets: ['es2015', 'stage-0', 'react']
}
}]
},
...
]
}