Skip to content

Instantly share code, notes, and snippets.

View js2me's full-sized avatar
🚙
I may be slow to respond.

Sergey S. Volkov js2me

🚙
I may be slow to respond.
View GitHub Profile
@js2me
js2me / vscode_dark++.css
Last active October 26, 2022 11:19
VS code common dark theme with neon highlights
.mtk13 {
color: #9cdcfe;
text-shadow: 0 0 2px #100c0f, 0 0 5px #ffdda926, 0 0 10px #fff3;
}
.mtk12 {
color: #ffdda9;
text-shadow: 0 0 2px #100c0f, 0 0 5px #ffdda926, 0 0 10px #fff3;
}
export default {
state: { firstName: '', lastName: '' }
changeAuthData(name, value) {
this.setState({
...this.state,
[name]: value
})
}
}
// login component
import { connect } from 'react-stonex
const Login = ({ firstName, lastName, changeAuthData }) => (
<div>
<input value={firstName} onChange={e => this.changeAuthData('firstName', e.target.value)} />
<input value={lastName} onChange={e => this.changeAuthData('lastName', e.target.value)} />
</div>
)
class Login extends React.Component {
changeForm = ({ target }) => {
this.setState({ [target.name]: target.value })
}
render() {
const { firstName, lastName } = this.state
return (
// ./modules/index.js
// don't worry about context. It links when module attaching to the store!
// Also all methods (like 'this.setState' ) from StonexModule class automatic will been inherited
const pureModule = {
state: {},
addItem(item){
this.setState({...this.state, [item.name]: item })
}
}
import { StonexModule } from 'stonex'
class UsersModule extends StonexModule {
state = []
addUser = user => this.setState([...this.state, user])
removeAllUsers = () => this.resetState()
}
export default UsersModule
// ./modules/index.js
import UsersModule from './UsersModule'
import AuthModule from './AuthModule'
import ModalsModule from './ModalsModule'
const modules = {
users: UsersModule,
auth: AuthModule,
modals: ModalsModule
}
// store.js
import { StonexStore } from 'stonex'
import modules from './modules'
import Logger from './modifiers/Logger'
import AppStateWorker from './common/AppStateWorker'
const storeConfiguration = {
modifiers: [ // middlewares
// store.js
import { StonexStore } from 'stonex'
import modules from './modules'
const store = new StonexStore(modules)
@js2me
js2me / unixTimeToDate.js
Created April 18, 2019 09:57
convert unix time to date
/**
* @name unixTimeToDate
*
* @param {number} unixTimeStamp
* @param {boolean} fromNow = add current time to unix timestamp
*
* @returns {Date} JavaScript Date type
*/
export const unixTimeToDate = (unixTimeStamp, fromNow = false) =>