Skip to content

Instantly share code, notes, and snippets.

View aigoncharov's full-sized avatar

Andrey Goncharov aigoncharov

View GitHub Profile
@aigoncharov
aigoncharov / react-no-context-1.jsx
Last active December 29, 2018 09:30
react-example
class Family extends React.Component {
state = { funds: 100 }
render () {
return <Dad name={this.state.funds}/>
}
}
class Dad extends React.Component {
render () {
@aigoncharov
aigoncharov / ngrx.js
Last active December 29, 2018 09:24
angular-example
const actionTypeSpendInit = 'SPEND_INIT'
const actionTypeSpendSuccess = 'SPEND_SUCCESS'
const actionTypeSpendError = 'SPEND_ERROR'
class ActionSpendInit {
type = actionTypeSpendInit
constructor(public payload)
}
class ActionSpendSuccess {
type = actionTypeSpendSuccess
@aigoncharov
aigoncharov / .eslintignore
Last active October 22, 2020 18:39
Initializing new TypeScript project
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage
const reducerLoading = (actionInit, actionSuccess, actionError) => (
state = false,
action,
) => {
switch (action.type) {
case actionInit.type:
return true
case actionSuccess.type:
return false
case actionError.type:
class CatsGetInit extends ActionStandard {}
class CatsGetSuccess extends ActionStandard {}
class CatsGetError extends ActionStandard {}
const reducerCatsLoading = createReducer(
false,
reducerLoadingMap(CatsGetInit, CatsGetSuccess, CatsGetError),
)
const reducerCatsData = createReducer(undefined, {
[CatsGetSuccess.type]: () => action.payload,
class CatsGetInit {}
class CatsGetSuccess {
constructor(responseData) {
this.payload = responseData
}
}
class CatsGetError {
constructor(error) {
this.payload = error
this.error = true
class CatsGetInit {
constructor() {
this.type = this.constructor.name
}
}
const reducerCats = (state, action) => {
switch (action.type) {
case CatsGetInit.name:
return {
...state,
class CatsGetInit {
get static type () {
return `prefix/${this.name}`
}
constructor () {
this.type = this.constructor.type
}
}
const reducerCats = (state, action) => {
switch (action.type) {
class ActionStandard {
get static type () {
return `prefix/${this.name}`
}
constructor(payload) {
this.type = this.constructor.type
this.payload = payload
this.error = payload instanceof Error
}
}
class GlobalErrorInit extends ActionStandard {}
class GlobalErrorClear extends ActionStandard {}
const reducerError = createReducer(undefined, {
[GlobalErrorInit.type]: (state, action) => action.payload,
[GlobalErrorClear.type]: (state, action) => undefined,
})