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
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.catch | |
import kotlinx.coroutines.flow.emitAll | |
import kotlinx.coroutines.flow.first | |
import kotlinx.coroutines.flow.flow | |
import kotlinx.coroutines.flow.map | |
import kotlinx.coroutines.flow.onStart | |
data class Resource<out T>(val status: Status, val data: T?, val exception: Throwable?) { | |
operator fun invoke(): T? { |
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
interface ApiClient { | |
suspend fun getTodos(): List<Todo> | |
} | |
class Repo(private val apiClient: ApiClient) { | |
suspend fun getTodos(): Result<List<Todo>> = runApiRequest { | |
apiClient.getTodos() | |
} | |
} |
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
import { useLayoutEffect } from "react" | |
export const useResizeEffect = (effect, deps = []) => { | |
// might need to wrap effect in a useCallback | |
useLayoutEffect(() => { | |
effect() | |
window.addEventListener('resize', effect) | |
return () => window.removeEventListener('resize', effect) | |
}, deps) | |
} |
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
const express = require('express'); | |
const app = express(); | |
const swaggerUi = require('swagger-ui-express'); | |
// './swagger.json' refers to the api documentation file generated through postman and converted through Apimatic | |
// it could be named anything else e.g. converted.json or api-docs.json | |
const swaggerDocument = require('./swagger.json'); | |
// '/api-docs' refers to the url or route path through which the documentation is to be served | |
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); |