Created
March 20, 2020 07:52
-
-
Save dmitryshelomanov/d00ca791755880b24f6be8dfe6d65657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import { type Store, combine, forward } from "effector" | |
import { createGate } from "effector-react" | |
import { mapTo, createListFetching } from "@lib/effector-extend" | |
import type { GeoPoint, Event as CardEvent, Place } from "@lib/ws" | |
import { | |
wsSearchForPlacecEvents, | |
$likes, | |
combineEventsWithLikesState, | |
} from "@features/events" | |
import { $currentGeoPoint } from "@features/common" | |
import { | |
type MainFilterStateWithoutRadius, | |
type TimeFilterState, | |
filters, | |
} from "@features/filter" | |
type E = CardEvent & { place: Place } | |
type Params = { | |
...GeoPoint, | |
...TimeFilterState, | |
...MainFilterStateWithoutRadius, | |
placeId: string, | |
} | |
const { mainFilter, timeFilter } = filters | |
export const EventsGate = createGate<{ placeId: string }>() | |
const $searchState = combine({ | |
position: $currentGeoPoint, | |
mainFilterState: mainFilter.$filterStateWithoutRadius, | |
parsedTimeState: timeFilter.$parsedTimeState, | |
gateState: EventsGate.state, | |
}).map(({ position, mainFilterState, parsedTimeState, gateState }) => ({ | |
...position, | |
...mainFilterState, | |
...parsedTimeState, | |
placeId: gateState.placeId, | |
})) | |
export const events = createListFetching<Params, E>({ | |
api: wsSearchForPlacecEvents, | |
$params: $searchState, | |
customReset: mapTo(EventsGate.close), | |
}) | |
export const $eventsList: Store<Array<E>> = combine( | |
events.$list, | |
$likes, | |
// $FlowFixMe | |
combineEventsWithLikesState, | |
) | |
forward({ from: mapTo(EventsGate.open), to: events.firstFetch }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment