Skip to content

Instantly share code, notes, and snippets.

@SuperOleg39
Last active February 28, 2019 10:03
Show Gist options
  • Select an option

  • Save SuperOleg39/d61ae73bc41f69393ba7671df2e6ea58 to your computer and use it in GitHub Desktop.

Select an option

Save SuperOleg39/d61ae73bc41f69393ba7671df2e6ea58 to your computer and use it in GitHub Desktop.
Цикл API + Store + UI:
1) Модели в API
API/EntityFoo {
id,
bars: [ API/EntityBar ],
bazs: [ API/EntityBaz ],
…otherProps
}
API/EntityBar {
id,
…otherProps
}
API/EntityBaz {
id,
foo: API/EntityFoo,
…otherProps
}
2) Структура Store
Store {
entities {
Store/Foo {
id,
bars: [ id ],
bazs: [ id ],
…otherProps
}
Store/Bar {
id,
…otherProps
}
Store/Baz {
id,
foo: id,
…otherProps
}
}
feature {
fooList: [ id ]
}
}
3) Сохранение данных из API в Store
fetchFooList = (response: [ API/EntityFoo ]) => {
Store.save(normalize(response, shema))
}
4) Доступ к данным из Store в UI
featureFooListSelector = (state: Store): [ API/EntityFoo ] => {
return denormalize(state.feature.fooList, state.entities, shema)
}
5) UI
FeatureProps {
fooList: [ API/EntityFoo ],
fetchFooList: Function
}
component Feature = (props: FeatureProps) => JSX
component ConnectedFeature = connect(featureFooListSelector, fetchFooList)(Feature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment