Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const decoder = flow(
ApiPayloadSchema.decode,
E.mapLeft(errors => failure(errors).join('\n'))
)
function getRandomGif(topic: string): cmd.Cmd {
const url = `https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=${topic}`
return pipe(
http.get(url, decoder),
http.send(e => newGif(E.either.map(e, a => a.data.image_url)))
)
}
// --- Update
const gifUrlLens = Lens.fromProp()('gifUrl')
export function update(msg: Msg, model: Model): [Model, cmd.Cmd] {
switch (msg.type) {
case 'MorePlease':
return [gifUrlLens.set(O.none)(model), getRandomGif(model.topic)]
case 'NewGif':
return [gifUrlLens.set(O.some(msg.result))(model), cmd.none]
}
throw new Error('err')
}
// --- View
export function view(model: Model): Html {
return dispatch => (
<div></div>
/**
* @since 0.2.0
*/
export const getRing = <s>(R: Ring>): Ring<s> => R
/**
* @since 0.2.0
*/
export const getField = <s>(F: Field>): Field<s> => F
//
// isos
//
const anyIso = new Iso(unsafeCoerce, unsafeCoerce)
/**
* @since 0.2.0
*/
export function iso<s>(): Iso> {
return anyIso
}
//
// prisms
//
/**
* @since 0.2.0
*/
export interface Concat, N2 extends Newtype>></s></s></s></s></s>
it('should allow optic management', () => {
const person: Person = {
name: 'Giulio',
age: age.wrap(43)
}
const ageLens = Lens.fromProp()('age').compose(age.asLens())
assert.deepEqual(ageLens.set(44)(person), {
name: 'Giulio',
age: 44
})
})
})
t: Traversal,
oai: OpenAPIObject,
p: PathItem,
): Parameter[] =>
t
.composePrism(
new Prism(
s =>
isReference(s)
? getParameterFromRef(oai, s.$ref.split("/")[3])
: some(s),
a => a,
),
)
.composePrism(
new Prism(
s =>
s.in === (header ? "header" : "query") && s.required ? some(s) : none,
a => a,
),
)
.composeGetter(new Getter(i => i))
.getAll(p)
.filter(a =>
a.schema ? !isNone(schemaPrism(oai).getOption(a.schema)) : false,
)
.map(b => ({
...b,
schema: b.schema
? isReference(b.schema)
? changeRef(b.schema)
: changeRefs(b.schema)
new Prism(
s =>
isReference(s)
? getParameterFromRef(oai, s.$ref.split("/")[3])
: some(s),
a => a,
),
)
.composePrism(
new Prism(
s =>
s.in === (header ? "header" : "query") && s.required ? some(s) : none,
a => a,
),
)
.composeGetter(new Getter(i => i))
.getAll(p)
.filter(a =>
a.schema ? !isNone(schemaPrism(oai).getOption(a.schema)) : false,
)
.map(b => ({
...b,
schema: b.schema
? isReference(b.schema)
? changeRef(b.schema)
: changeRefs(b.schema)
: { type: "string" },
}));
import { Lens } from 'monocle-ts';
export interface BrowserState {
pageTitle: string;
pageUrl: string;
}
export const pageTitle = Lens.fromProp()('pageTitle');
export const pageUrl = Lens.fromProp()('pageUrl');
export enum BrowserActionTypes {
SyncBrowser = 'SYNC_BROWSER',
}
elemC(eqString)(arg),
);
const badgeDisplayCodec = fromRefinement(
'badgeDisplay',
(x): x is BadgeDisplay => t.string.is(x) && isBadgeDisplayOpt(x),
);
const settingsCodec = t.type({
theme: optionFromNullable(themeCodec),
badgeDisplay: optionFromNullable(badgeDisplayCodec),
});
export type Settings = t.TypeOf;
const theme = Lens.fromProp()('theme');
const badgeDisplay = Lens.fromProp()('badgeDisplay');
export const saveSettings = (opts: Settings): TaskEither => setSyncStorage(opts);
const getSettings: TaskEither = pipe(
getSyncStorage(['theme', 'badgeDisplay']),
T.map(E.chain(decode(settingsCodec))),
);
export const getActiveTheme: TaskEither> = pipe(
getSettings,
T.map(E.map(flow(
theme.get,
O.chain(O.fromPredicate(isTheme)),
))));
import { Lens } from 'monocle-ts';
import { Theme } from 'Modules/settings';
export { Theme };
export interface UserState {
hasBinaryComms: boolean;
activeTheme: Theme;
displayOpenAllBookmarksConfirmation: boolean;
page: Page;
}
export const hasBinaryComms = Lens.fromProp()('hasBinaryComms');
export const activeTheme = Lens.fromProp()('activeTheme');
export const displayOpenAllBookmarksConfirmation = Lens.fromProp()('displayOpenAllBookmarksConfirmation');
export const page = Lens.fromProp()('page');
export enum UserActionTypes {
SetHasBinaryComms = 'SET_HAS_BINARY_COMMS',
SetActiveTheme = 'SET_ACTIVE_THEME',
SetDisplayOpenAllBookmarksConfirmation = 'SET_OPEN_ALL_BOOKMARKS_CONFIRMATION',
SetPage = 'SET_PAGE',
}
export enum Page {
Search,
AddBookmark,
EditBookmark,
StagedGroupsList,
StagedGroup,
}
/*
* Bookmark as stored in LocalStorage.
*/
export interface LocalBookmark extends LocalBookmarkUnsaved {
id: number;
}
export interface LocalBookmarkWeighted extends LocalBookmark {
weight: URLMatch;
}
export const id = Lens.fromProp()('id');
export const title = Lens.fromProp()('title');
export const weight = Lens.fromProp()('weight');
const ordTitle: Ord = contramap(title.get)(ordString);
const ordWeight: Ord = contramap(weight.get)(ordURLMatch)
export const ordLocalBookmarkWeighted = getSemigroup().concat(ordWeight, ordTitle);
/**
* Filter out bookmarks that do not perfectly match the provided test.
*/
export const filterBookmarks = (bookmarks: Array, test: ParsedInputResult): Array =>
bookmarks.filter((bookmark) => {
if (!includesCI(test.name)(bookmark.title)) return false;
if (test.desc.some(d => !includesCI(d)(bookmark.desc))) return false;
if (test.url.some(u => !includesCI(u)(bookmark.url))) return false;
if (test.tags.some(t => !bookmark.tags.some(tag => includesCI(t)(tag)))) return false;
import { Lens } from 'monocle-ts';
import { LocalBookmark } from 'Modules/bookmarks';
export interface StagedBookmarksGroup {
id: number;
time: number;
bookmarks: Array;
}
export const id = Lens.fromProp()('id');
export const time = Lens.fromProp()('time');
export const bookmarks = Lens.fromProp()('bookmarks');