How to use the epubjs/lib/utils/core.defer function in epubjs

To help you get started, we’ve selected a few epubjs 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 futurepress / epubjs-rn / src / EpubViewManager.js View on Github external
prepend(section) {
    var displaying = new core.defer();
    let sections = [section];

    // if (this.scrolling) {
    //   // queue
    //   console.log("queue");
    //   return;
    // }
    if (this.state.sections.includes(section)) {
      return;
    }

    if (this.fixed && this.spreads) {
      let prevSection = section.prev();
      prevSection && sections.unshift(prevSection);
    }
github futurepress / epubjs-rn / src / EpubView.js View on Github external
expand() {
    var width, height;
    var expanded;
    var expanding;
    __DEV__ && console.log("expanding", this.index);
    // if (this.expanding || this.loading) {
    //   return;
    // }
    this.expanding = true;

    if (this.props.layout.name === "pre-paginated") {
      // this.expanding = false;
        var defered = new core.defer();
        let width = this.props.columnWidth;
        let marginLeft = 0;

        if (this.props.spreads && this.props.section.index === 0) {
          width = this.props.columnWidth * 2;
          marginLeft = this.props.columnWidth;
        }

        if (this.props.spreads &&
            this.props.section.index === this.props.lastSectionIndex &&
            this.props.section.index % 2 > 0 ) {
          width = this.props.columnWidth * 2;
        }

        this.setState({
          width,
github futurepress / epubjs-rn / src / EpubView.js View on Github external
load() {
    var loaded = new core.defer();

    if (!this.sectionRendering) {
      this.sectionRendering = this.props.section.render(this.props.request);
    }

    // console.log("loading", this.props.section.index);

    if (!this.state.contents) {
      this.sectionRendering.then((contents) => {
          if (!this.mounted) {
            return; // Prevent updating an unmounted component
          }
          this.setState({ contents }, () => {

            this.rendering.resolve();
            loaded.resolve();
github futurepress / epubjs-rn / src / EpubView.js View on Github external
}).then((h) => {
        var defered = new core.defer();
        var margin = 0;

        height = h;
        // console.log("Height", height);

        this.setState({ height, margin }, () => {
          this.expanding = false;
          defered.resolve();
        });

        return defered.promise;
      });
    }
github futurepress / epubjs-rn / src / EpubViewManager.js View on Github external
append(section) {
    var displaying = new core.defer();
    let sections = [section];

    if (this.state.sections.includes(section)) {
      return;
    }

    if (this.fixed && this.spreads) {
      let nextSection = section.next();
      nextSection && sections.push(nextSection);
    }

    // __DEV__ && console.log("append", section.index);

    this.setState({
        sections: this.state.sections.concat(sections),
      },
github futurepress / epubjs-rn / src / EpubView.js View on Github external
viewport: () => this.ask("viewport"),
      addStylesheet: (src) => this.ask("addStylesheet", [src]),
      addStylesheetRules: (rules) => this.ask("addStylesheetRules", [rules]),
      addScript: (src) => this.ask("addScript", [src]),
      range: (_cfi, ignoreClass) => this.ask("addStylesheet", [_cfi, ignoreClass]),
      map: (map) => this.ask("map", [map]),
      columns: (width, height, columnWidth, gap) => this.ask("columns", [width, height, columnWidth, gap]),
      fit: (width, height) => this.ask("fit", [width, height]),
      size: (width, height) => this.ask("size", [width, height]),
      mapPage: (cfiBase, start, end) => this.ask("mapPage", [cfiBase, start, end]),
      locationOf: (target) => this.ask("locationOf", [target]),
    }

    EventEmitter(this.contents);

    this.rendering = new core.defer();
    this.rendered = this.rendering.promise;

    this.loading = true;
    this.expanded = false;
  }
github futurepress / epubjs-rn / src / EpubView.js View on Github external
locationOf: (target) => this.ask("locationOf", [target]),
      setCfiBase: (cfiBase) => this.ask("setCfiBase", [cfiBase]),
      highlight: (cfiRange, data) => this.ask("highlight", [cfiRange, data]),
      underline: (cfiRange, data) => this.ask("underline", [cfiRange, data]),
      mark: (cfiRange, data) => this.ask("mark", [cfiRange, data]),
      unhighlight: (cfiRange) => this.ask("unhighlight", [cfiRange]),
      ununderline: (cfiRange) => this.ask("ununderline", [cfiRange]),
      unmark: (cfiRange) => this.ask("unmark", [cfiRange])
    }

    EventEmitter(this.contents);

    this.rendering = new core.defer();
    this.rendered = this.rendering.promise;

    this.displaying = new core.defer();
    this.displayed = this.displaying.promise;

    this.loading = true;
    this.expanded = false;

    this.index = this.props.section && this.props.section.index;
    this.contents.sectionIndex = this.index;
  }
github futurepress / epubjs-rn / src / EpubView.js View on Github external
ask(method, args) {
    var asking = new core.defer();
    var promiseId = asking.id;

    if(method in this.waiting) {
      this.waiting[promiseId].push(asking)
    } else {
      this.waiting[promiseId] = [asking];
    }

    this.sendToBridge(method, args, promiseId);

    return asking.promise;
  }