How to use the kefir.constantError function in kefir

To help you get started, we’ve selected a few kefir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github intraxia / wp-gistpen / client / api / index.ts View on Github external
.flatMap(response => {
      // Can't guarantee any type of response on 500s
      if (response.status >= 500) {
        return Kefir.constantError(new ServerError(response));
      }

      if (response.status >= 400) {
        return Kefir.constantError(new ClientError(response));
      }

      return response.json().mapErrors(error => new JsonError(error));
    })
    .flatMap(body =>
github mAAdhaTTah / brookjs / packages / brookjs / src / domDelta / index.js View on Github external
let precheck$ = Kefir.constant('Configuration correct');

    if (typeof el === 'function') {
        el = el(document);

        if (!(el instanceof Kefir.Observable)) {
            precheck$ = Kefir.constantError(new TypeError(`type ${typeof el} returned from el is not valid`));
        }
    } else if (el instanceof Element) {
        el = Kefir.constant(el);
    } else {
        precheck$ = Kefir.constantError(new TypeError(`el of type ${typeof el} is not valid`));
    }

    if (typeof view !== 'function') {
        precheck$ = Kefir.constantError(new TypeError(`component of type ${typeof el} is not valid`));
    }

    if (typeof selectProps !== 'function') {
        precheck$ = Kefir.constantError(new TypeError(`selectProps of type ${typeof el} is not valid`));
    }

    return (actions$, state$) => precheck$
        .flatMap(documentIsLoaded)
        .flatMap(isLoaded =>
            isLoaded ?
                // ensures async consistency
                Kefir.later(0, true) :
                Kefir.fromEvents(document, 'DOMContentLoaded')
        )
        .flatMap(() => el)
        .take(1).takeErrors(1)
github researchspace / researchspace / metaphacts-platform / web / src / main / api / sparql / SparqlUtil.ts View on Github external
export function parseQueryAsync(query: string): Kefir.Property {
  try {
    return Kefir.constant(parseQuery(query));
  } catch (e) {
    console.error('Error while parsing the query: ' + e);
    return Kefir.constantError(e);
  }
}
github researchspace / researchspace / metaphacts-platform / web / src / main / api / async / BatchedPool.ts View on Github external
.flatMap<output>(result =&gt; {
        if (result.batch) {
          return Kefir.constant(result.batch.get(input));
        } else {
          return Kefir.constantError(result.error);
        }
      }).take(1).takeErrors(1).toProperty();
  }</output>
github researchspace / researchspace / researchspace / web / src / main / data / iiif / ImageAnnotationService.ts View on Github external
function getImageBindings(
  imageOrRegion: Rdf.Iri,
  imageIdPattern: string,
  repository: string
): Kefir.Property {
  const query = cloneQuery(IMAGE_REGION_INFO_QUERY);
  let imageIdPatterns: SparqlJs.Pattern[];
  try {
    imageIdPatterns = SparqlUtil.parsePatterns(imageIdPattern, query.prefixes);
  } catch (err) {
    return Kefir.constantError(new WrappingError(
      `Failed to parse image ID patterns '${imageIdPattern}':`, err));
  }

  new PatternBinder('__imageIdPattern__', imageIdPatterns).sparqlQuery(query);
  const parametrizedQuery = SparqlClient.setBindings(query, {'__iri__': imageOrRegion});

  return SparqlClient.select(parametrizedQuery, {context: {repository: repository}})
}
github intraxia / wp-gistpen / client / api / index.ts View on Github external
        errs => Kefir.constantError(new ValidationError(errs)),
        body => Kefir.constant(success(body)),
github researchspace / researchspace / researchspace / web / src / main / components / iiif / mirador / MiradorAnnotationEndpoint.ts View on Github external
deleteAnnotation(annotationId: string, onSuccess: () =&gt; void, onError: () =&gt; void) {
    const task = this.endpoint.remove
      ? this.endpoint.remove(Rdf.iri(annotationId))
      : Kefir.constantError(new Error(
        'AnnotationEndpoint.delete is not implemented'));

    task.onValue(onSuccess).onError(onError);
  }
}
github ivan-kleshnin / unredux / examples / 7.2.crud-ssr / server / ssr / index.js View on Github external
let timeoutError = (delayMs) =>
  K.later(delayMs, K.constantError(new Error("timeout"))).flatMap()
github mAAdhaTTah / brookjs / packages / brookjs-cli / src / services / scaffold.js View on Github external
const exec = callback => {
        if (typeof spec.content === 'string') {
            return callback(selectPath(state, spec), spec.content)
                .map(() => fileCreated(spec.path));
        }

        if (typeof spec.template === 'string') {
            return template(spec.template)
                .map(tmpl => tmpl(selectContext(state, spec)))
                .flatMap(content => callback(selectPath(state, spec), content))
                .map(() => fileCreated(spec.path));
        }

        return Kefir.constantError(new TypeError(`Invalid spec: ${spec.path}. No content or template.`));
    };
github intraxia / wp-gistpen / client / deltas / repoDelta.ts View on Github external
                  errs => Kefir.constantError(new ValidationError(errs)),
                  Kefir.constant,

kefir

Reactive Programming library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory usage

MIT
Latest version published 4 years ago

Package Health Score

57 / 100
Full package analysis