rxjs#of JavaScript Examples
The following examples show how to use
rxjs#of.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From sampo-ui with MIT License | 6 votes |
fetchResultCountEpic = (action$, state$) => action$.pipe(
ofType(FETCH_RESULT_COUNT),
withLatestFrom(state$),
mergeMap(([action, state]) => {
const { resultClass, facetClass } = action
const params = stateToUrl({
facets: state[`${facetClass}Facets`].facets
})
const requestUrl = `${apiUrl}/faceted-search/${resultClass}/count`
return ajax({
url: requestUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: params
}).pipe(
map(ajaxResponse => updateResultCount({
resultClass,
data: ajaxResponse.response.data,
sparqlQuery: ajaxResponse.response.sparqlQuery
})),
catchError(error => of({
type: FETCH_RESULT_COUNT_FAILED,
resultClass,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #2
Source File: index.js From sampo-ui with MIT License | 6 votes |
fullTextSearchEpic = (action$, state$) => action$.pipe(
ofType(FETCH_FULL_TEXT_RESULTS),
withLatestFrom(state$),
debounceTime(500),
switchMap(([action, state]) => {
const requestUrl = `${apiUrl}/full-text-search?q=${action.query}`
return ajax.getJSON(requestUrl).pipe(
map(response => updateResults({
resultClass: 'fullTextSearch',
data: response.data,
sparqlQuery: response.sparqlQuery,
query: action.query,
jenaIndex: action.jenaIndex
})),
catchError(error => of({
type: FETCH_RESULTS_FAILED,
resultClass: 'fullTextSearch',
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #3
Source File: index.js From sampo-ui with MIT License | 6 votes |
fetchByURIEpic = (action$, state$) => action$.pipe(
ofType(FETCH_BY_URI),
withLatestFrom(state$),
mergeMap(([action, state]) => {
const { perspectiveID, resultClass, facetClass, uri } = action
const params = stateToUrl({
perspectiveID,
facets: facetClass == null ? null : state[`${facetClass}Facets`].facets,
facetClass
})
const requestUrl = `${apiUrl}/${resultClass}/page/${encodeURIComponent(uri)}`
return ajax({
url: requestUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: params
}).pipe(
map(ajaxResponse => updateInstanceTable({
resultClass,
data: ajaxResponse.response.data,
sparqlQuery: ajaxResponse.response.sparqlQuery
})),
catchError(error => of({
type: FETCH_BY_URI_FAILED,
resultClass: resultClass,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #4
Source File: index.js From sampo-ui with MIT License | 6 votes |
clientFSFetchResultsEpic = (action$, state$) => action$.pipe(
ofType(CLIENT_FS_FETCH_RESULTS),
withLatestFrom(state$),
debounceTime(500),
switchMap(([action, state]) => {
const { perspectiveID, jenaIndex } = action
const federatedSearchState = state[perspectiveID]
const selectedDatasets = pickSelectedDatasets(federatedSearchState.datasets)
const dsParams = selectedDatasets.map(ds => `dataset=${ds}`).join('&')
let requestUrl
if (action.jenaIndex === 'text') {
requestUrl = `${apiUrl}/federated-search?q=${action.query}&${dsParams}&perspectiveID=${perspectiveID}`
} else if (action.jenaIndex === 'spatial') {
const { latMin, longMin, latMax, longMax } = federatedSearchState.maps.boundingboxSearch
requestUrl = `${apiUrl}/federated-search?latMin=${latMin}&longMin=${longMin}&latMax=${latMax}&longMax=${longMax}&${dsParams}&perspectiveID=${perspectiveID}`
}
return ajax.getJSON(requestUrl).pipe(
map(response => clientFSUpdateResults({
results: response,
jenaIndex
})),
catchError(error => of({
type: CLIENT_FS_FETCH_RESULTS_FAILED,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #5
Source File: index.js From sampo-ui with MIT License | 6 votes |
fetchSimilarDocumentsEpic = (action$, state$) => action$.pipe(
ofType(FETCH_SIMILAR_DOCUMENTS_BY_ID),
withLatestFrom(state$),
mergeMap(([action]) => {
const { resultClass, id, modelName, resultSize } = action
const requestUrl = `${documentFinderAPIUrl}/top-similar/${modelName}/${id}?n=${resultSize}`
return ajax.getJSON(requestUrl).pipe(
map(res => updateInstanceTableExternal({
resultClass,
data: res.documents || null
})),
catchError(error => of({
type: FETCH_SIMILAR_DOCUMENTS_BY_ID_FAILED,
resultClass: action.resultClass,
id: action.id,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #6
Source File: index.js From sampo-ui with MIT License | 6 votes |
fetchGeoJSONLayersBackendEpic = (action$, state$) => action$.pipe(
ofType(FETCH_GEOJSON_LAYERS_BACKEND),
withLatestFrom(state$),
mergeMap(([action]) => {
const { layerIDs /* bounds */ } = action
// const { latMin, longMin, latMax, longMax } = boundsToValues(bounds)
const params = {
layerID: layerIDs
// latMin,
// longMin,
// latMax,
// longMax
}
const requestUrl = `${apiUrl}/wfs?${querystring.stringify(params)}`
return ajax.getJSON(requestUrl).pipe(
map(res => updateGeoJSONLayers({
payload: res
})),
catchError(error => of({
type: SHOW_ERROR,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #7
Source File: index.js From sampo-ui with MIT License | 6 votes |
fetchKnowledgeGraphMetadataEpic = (action$, state$) => action$.pipe(
ofType(FETCH_KNOWLEDGE_GRAPH_METADATA),
withLatestFrom(state$),
mergeMap(([action]) => {
const requestUrl = `${apiUrl}/void/${action.perspectiveID}/${action.resultClass}`
return ajax({
url: requestUrl,
method: 'GET'
}).pipe(
map(ajaxResponse => updateKnowledgeGraphMetadata({
resultClass: action.resultClass,
data: ajaxResponse.response.data ? ajaxResponse.response.data[0] : null,
sparqlQuery: ajaxResponse.response.sparqlQuery
})),
catchError(error => of({
type: FETCH_KNOWLEDGE_GRAPH_METADATA_FAILED,
perspectiveID: action.resultClass,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #8
Source File: KrakenExchangeClient.js From invizi with GNU General Public License v3.0 | 6 votes |
// fetch deposits AND withdrawal
getDepositsObs (apiKey, symbolCurrencyPair = undefined, params = {}) {
let counter = -1
this.initializeApiKey(apiKey)
const query = () => {
counter++
return this.ccxt.fetchLedger(undefined, undefined, undefined, {ofs: counter * 50})
}
const trades$ = defer(query)
let load$ = new BehaviorSubject('')
const whenToRefresh$ = of('').pipe(
delay(5000),
tap(_ => load$.next('')),
skip(1))
const byDepositAndWithdrawal = trade => trade && ['deposit', 'withdrawal'].includes(trade.info.type)
const poll$ = concat(trades$, whenToRefresh$)
return load$.pipe(
concatMap(_ => poll$),
takeWhile(data => data.length > 0),
map(data => ({errors: [], data: data.filter(byDepositAndWithdrawal).map(parseLedger)})),
catchError(error$ => of({errors: [error$.toString()], data: []})))
}
Example #9
Source File: KrakenExchangeClient.js From invizi with GNU General Public License v3.0 | 6 votes |
getMyTradesObs (apiKey, symbolCurrencyPair = undefined, params = {}) {
let counter = -1
this.initializeApiKey(apiKey)
const fetchTrades = () => {
counter++
return super.getMyTrades(apiKey, undefined, {ofs: counter * 50})
}
const trades$ = defer(() => fetchTrades())
let load$ = new BehaviorSubject('')
const whenToRefresh$ = of('').pipe(
delay(5000),
tap(_ => load$.next('')),
skip(1))
const poll$ = concat(trades$, whenToRefresh$)
let result$ = load$.pipe(
concatMap(_ => poll$),
takeWhile(data => data.length > 0),
map(data => ({errors: [], data})),
catchError(error$ => {
return of({errors: [error$.toString()], data: []})
}))
return result$
}
Example #10
Source File: index.js From sampo-ui with MIT License | 5 votes |
fetchPaginatedResultsEpic = (action$, state$) => action$.pipe(
ofType(FETCH_PAGINATED_RESULTS),
withLatestFrom(state$),
mergeMap(([action, state]) => {
const { resultClass, facetClass, sortBy } = action
const { page, pagesize, sortDirection } = state[resultClass]
const params = stateToUrl({
facets: state[`${facetClass}Facets`].facets,
facetClass: null,
page,
pagesize,
sortBy,
sortDirection
})
const requestUrl = `${apiUrl}/faceted-search/${resultClass}/paginated`
// https://rxjs-dev.firebaseapp.com/api/ajax/ajax
return ajax({
url: requestUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: params
}).pipe(
map(ajaxResponse =>
updatePaginatedResults({
resultClass,
data: ajaxResponse.response.data,
sparqlQuery: ajaxResponse.response.sparqlQuery
})),
// https://redux-observable.js.org/docs/recipes/ErrorHandling.html
catchError(error => of({
type: FETCH_PAGINATED_RESULTS_FAILED,
resultClass,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #11
Source File: index.js From sampo-ui with MIT License | 5 votes |
fetchResultsEpic = (action$, state$) => action$.pipe(
ofType(FETCH_RESULTS),
withLatestFrom(state$),
mergeMap(([action, state]) => {
const { perspectiveID, resultClass, facetClass, limit, optimize } = action
const params = stateToUrl({
perspectiveID,
facets: facetClass ? state[`${facetClass}Facets`].facets : null,
facetClass,
uri: action.uri ? action.uri : null,
limit,
optimize
})
const requestUrl = `${apiUrl}/faceted-search/${resultClass}/all`
// https://rxjs-dev.firebaseapp.com/api/ajax/ajax
return ajax({
url: requestUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: params
}).pipe(
map(ajaxResponse => updateResults({
resultClass,
data: ajaxResponse.response.data,
sparqlQuery: ajaxResponse.response.sparqlQuery,
order: action.order
})),
catchError(error => of({
type: FETCH_RESULTS_FAILED,
resultClass,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #12
Source File: index.js From sampo-ui with MIT License | 5 votes |
fetchInstanceAnalysisEpic = (action$, state$) => action$.pipe(
ofType(FETCH_INSTANCE_ANALYSIS),
withLatestFrom(state$),
mergeMap(([action, state]) => {
const { resultClass, facetClass, fromID, toID, period, province } = action
const params = stateToUrl({
facets: facetClass ? state[`${facetClass}Facets`].facets : null,
facetClass,
uri: action.uri ? action.uri : null,
fromID,
toID,
period,
province
})
const requestUrl = `${apiUrl}/faceted-search/${resultClass}/all`
// https://rxjs-dev.firebaseapp.com/api/ajax/ajax
return ajax({
url: requestUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: params
}).pipe(
map(ajaxResponse => updateInstanceAnalysisData({
resultClass,
data: ajaxResponse.response.data,
sparqlQuery: ajaxResponse.response.sparqlQuery
})),
catchError(error => of({
type: FETCH_RESULTS_FAILED,
resultClass,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #13
Source File: index.js From sampo-ui with MIT License | 5 votes |
fetchFacetEpic = (action$, state$) => action$.pipe(
ofType(FETCH_FACET),
withLatestFrom(state$),
mergeMap(([action, state]) => {
const { facetClass, facetID, constrainSelf } = action
const facets = state[`${facetClass}Facets`].facets
const facet = facets[facetID]
const { sortBy = null, sortDirection = null } = facet
const params = stateToUrl({
facets,
sortBy,
sortDirection,
constrainSelf
})
const requestUrl = `${apiUrl}/faceted-search/${action.facetClass}/facet/${facetID}`
return ajax({
url: requestUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: params
}).pipe(
map(ajaxResponse => updateFacetValues({
facetClass,
id: ajaxResponse.response.id,
data: ajaxResponse.response.data || [],
flatData: ajaxResponse.response.flatData || [],
sparqlQuery: ajaxResponse.response.sparqlQuery
})),
catchError(error => of({
type: FETCH_FACET_FAILED,
facetClass,
facetID,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #14
Source File: index.js From sampo-ui with MIT License | 5 votes |
fetchFacetConstrainSelfEpic = (action$, state$) => action$.pipe(
ofType(FETCH_FACET_CONSTRAIN_SELF),
withLatestFrom(state$),
mergeMap(([action, state]) => {
const { facetClass, facetID } = action
const facets = state[`${facetClass}Facets`].facets
const facet = facets[facetID]
const { sortBy, sortDirection } = facet
const params = stateToUrl({
facets: facets,
sortBy: sortBy,
sortDirection: sortDirection,
constrainSelf: true
})
const requestUrl = `${apiUrl}/faceted-search/${action.facetClass}/facet/${facetID}`
return ajax({
url: requestUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: params
}).pipe(
map(ajaxResponse => updateFacetValuesConstrainSelf({
facetClass,
id: facetID,
data: ajaxResponse.response.data || [],
flatData: ajaxResponse.response.flatData || [],
sparqlQuery: ajaxResponse.response.sparqlQuery
})),
catchError(error => of({
type: FETCH_FACET_FAILED,
resultClass: facetClass,
id: action.id,
error: error,
message: {
text: backendErrorText,
title: 'Error'
}
}))
)
})
)
Example #15
Source File: KrakenExchangeClient.js From invizi with GNU General Public License v3.0 | 5 votes |
getWithdrawalsObs () {
return of('')
}
Example #16
Source File: index.js From discovery-mobile-ui with MIT License | 5 votes |
handleError = (error, message, type) => {
console.error(`${message}: `, error); // eslint-disable-line no-console
return of({
type: type ?? actionTypes.ERROR,
error: true,
payload: { message, error },
});
}