<div class="catalog-section" v-for="category in categories" :key="category.index">
<h2 class="catalog-section--title title-default">{{category.name}} {{category.id}}</h2>
<p class="catalog-section--label label-default" v-if="category.label">{{category.label}}</p>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4" v-for="item in posts.filter(item => item.category === category.id)" :key="item.index">
<product-item :item=item />
</div>
</div>
</div>
<div class="catalog-section" v-for="category in categories" :key="category.index">
<h2 class="catalog-section--title title-default">{{category.name}} {{category.id}}</h2>
<p class="catalog-section--label label-default" v-if="category.label">{{category.label}}</p>
<div class="row">
<template v-for="item in posts">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4" v-if="item.category === category.id" :key="item.index">
<product-item :item=item />
</div>
</template>
</div>
</div>
const socket = io('/path');
router.get('/api', async (ctx, next) => {
let messages; // получаю список из базы
knex.select().from('messages').timeout(1000).then(res => {
messages = JSON.stringify(res);
});
ctx.body = messages; // вывожу
});
let messages;
knex.select().from('messages').timeout(1000).then(res => {
messages = JSON.stringify(res);
});
import React, { useCallback, useRef } from 'react';
import ReactDOM from 'react-dom';
import { combineReducers, createStore } from 'redux';
import { Provider, connect } from 'react-redux';
// action type
const ADD_MESSAGE = 'ADD_MESSAGE';
// action creator
const addMessage = payload => ({
type: ADD_MESSAGE,
payload,
});
// reducer
const messages = (state = [], action) => {
switch (action.type) {
case ADD_MESSAGE:
return [...state, action.payload];
default:
return state;
}
};
// root reducer
const rootReducer = combineReducers({
messages,
});
// store
const store = createStore(rootReducer);
const App = ({ addMessage, messages }) => {
const inputRef = useRef(null);
const handler = useCallback(() => {
addMessage(inputRef.current.value);
inputRef.current.value = '';
}, [inputRef, addMessage]);
return (
<div>
<ul>
{messages.map((message, i) => (
<li key={i}>{message}</li>
))}
</ul>
<input ref={inputRef} />
<button onClick={handler}>Add Message</button>
</div>
);
};
const mapStateToProps = state => ({
messages: state.messages,
});
const mapDispatchToProps = {
addMessage,
};
const ConnectedApp = connect(
mapStateToProps,
mapDispatchToProps
)(App);
const root = (
<Provider store={store}>
<ConnectedApp />
</Provider>
);
const rootElement = document.getElementById('root');
ReactDOM.render(root, rootElement);
import React, { useCallback, useRef } from 'react';
import ReactDOM from 'react-dom';
import { combineReducers, createStore } from 'redux';
import { Provider, connect } from 'react-redux';
import { createAction, createReducer } from 'redux-act';
// action creator
const addMessage = createAction('ADD_MESSAGE');
// reducer
const messages = createReducer({}, []);
messages.on(addMessage, (state, message) => [...state, message]);
// root reducer
const rootReducer = combineReducers({
messages,
});
// store
const store = createStore(rootReducer);
const App = ({ addMessage, messages }) => {
const inputRef = useRef(null);
const handler = useCallback(() => {
addMessage(inputRef.current.value);
inputRef.current.value = '';
}, [inputRef, addMessage]);
return (
<div>
<ul>
{messages.map((message, i) => (
<li key={i}>{message}</li>
))}
</ul>
<input ref={inputRef} />
<button onClick={handler}>Add Message</button>
</div>
);
};
const mapStateToProps = state => ({
messages: state.messages,
});
const mapDispatchToProps = {
addMessage,
};
const ConnectedApp = connect(
mapStateToProps,
mapDispatchToProps,
)(App);
const root = (
<Provider store={store}>
<ConnectedApp />
</Provider>
);
const rootElement = document.getElementById('root');
ReactDOM.render(root, rootElement);
save_custom(): Observable<void> {
return this.createFile()
.pipe(
tap(() => this.save_order()),
);
async save_custom(): Promise<void> {
await this.createFile();
return await this.save_order();
const div = document.createElement("div");
const nodes = document.body.childNodes;
while (nodes.length) div.appendChild(nodes[0]);
document.body.appendChild(div);