Skip to content

Instantly share code, notes, and snippets.

View manojsinghnegiwd's full-sized avatar
🎯
Focusing

Manoj Singh Negi manojsinghnegiwd

🎯
Focusing
View GitHub Profile
function useReducer(reducer, initState) {
const [state, setState] = useState(initState);
const dispatch = useCallback((action) => {
const nextState = reducer(state, action)
setState(nextState)
}, [setState, state])
return [state, dispatch];
}
search.query("business")
search.loadProviders(searchUsingTerm)
const searchUsingType: SearchResultProvider = (searchTerm) => {
const data = [
{
"term": "facebook",
"type": "social"
},
{
"term": "twitter",
"type": "social"
},
search.query("business")
interface SearchResult {
term: string
type: string
}
type SearchResults = SearchResult[]
type SearchResultProvider = (searchTerm: string) => SearchResults
class SearchRecSys {
interface SearchResult {
term: string
type: string
}
type SearchResults = SearchResult[]
type SearchResultProvider = (searchTerm: string) => SearchResults
class SearchRecSys {
const searchUsingTerm: SearchResultProvider = (searchTerm) => {
const data = [
{
"term": "business",
"type": "term"
},
{
"term": "business tips",
"type": "term"
},
class SearchRecSys {
//..... our other code
query: SearchResultProvider = (searchTerm) => {
const results = this.providers.reduce(
(searchResults, item) => {
return searchResults.concat(item(searchTerm, this.data))
},[]
)
return results
}
class SearchRecSys {
//..... our other code
loadProviders = (
providers: SearchResultProvider | SearchResultProvider[]
): void => {
this.providers = this.providers.concat(providers)
}
//..... our other code
}