How to use fastdom - 10 common examples

To help you get started, we’ve selected a few fastdom 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 salesforce-ux / design-system / site / assets / scripts / shared / sticky.js View on Github external
calculate() {
    fastdom.measure(() => {
      this.refs.content.style.width = '';
      // Content
      const content = this.refs.content;
      const contentRect = content.getBoundingClientRect();
      const contentPadding = this.getPaddingTop(content);
      // Calculate the extra offset added by any other fixed elements above this one
      const fixedElements = this.fixedElements ? $(this.fixedElements) : [];
      const fixedOffset = fixedElements.reduce((offset, el) => {
        return offset + el.getBoundingClientRect().height;
      }, 0);
      this.setState({
        contentRect,
        contentTop: contentPadding + fixedOffset,
        scrollOffset: contentRect.top + window.pageYOffset - fixedOffset - contentPadding
      });
    });
github bigbluebutton / bigbluebutton / bigbluebutton-html5 / imports / ui / components / chat / message-list / message-list-item / message / component.jsx View on Github external
listenToUnreadMessages() {
    const {
      handleReadMessage,
      time,
      lastReadMessageTime,
    } = this.props;

    if (lastReadMessageTime > time) {
      return;
    }

    const node = this.text;

    fastdom.measure(() => {
      const {
        lastReadMessageTime: updatedLastReadMessageTime,
      } = this.props;
      // this function is called after so we need to get the updated lastReadMessageTime

      if (updatedLastReadMessageTime > time) {
        return;
      }

      if (isElementInViewport(node)) { // no need to listen, the message is already in viewport
        handleReadMessage(time);
      } else {
        this.addScrollListeners();
      }
    });
  }
github wellcometrust / wellcomecollection.org / client / js / components / eventbrite-ticket-button.js View on Github external
export function eventbriteTicketButton(el) {
  fastdom.measure(() => {
    const eventbriteId = el.getAttribute('data-eventbrite-ticket-id');

    fetch(`/eventbrite/button/events/${eventbriteId}/ticket_classes`)
      .then(resp => resp.json())
      .then(ticketButton => {
        fastdom.mutate(() => {
          // This is a nasty hack to update the event info bar
          if (ticketButton.onSaleStatus === 'sold_out') {
            const el = document.getElementById('js-event-booking-info');
            if (el) {
              el.parentNode.removeChild(el);
            }
          }
          el.innerHTML = ticketButton.html;
        });
      });
github salesforce-ux / design-system / site / assets / scripts / shared / sticky.js View on Github external
calculate(first) {
    fastdom.measure(() => {
      // Calculate the extra offset added by any other fixed elements above this one
      const fixedElementsAbove = this.props.fixedElementsAbove
        ? $(this.props.fixedElementsAbove) : [];
      const fixedOffsetAbove = fixedElementsAbove.reduce((offset, el) =>
        offset + el.getBoundingClientRect().height
      , 0);
      // Calculate the extra offset added by any other fixed elements below this one
      const fixedElementsBelow = this.props.fixedElementsBelow
        ? $(this.props.fixedElementsBelow) : [];
      const fixedOffsetBelow = fixedElementsBelow.reduce((offset, el) =>
        offset + el.getBoundingClientRect().height
      , 0);
      // Content
      const content = this.refs.content;
      const contentRect = content.getBoundingClientRect();
      const contentPadding = this.getPadding(content, PADDING_IDENTITY());
github CatchLabs / vue-list-view / lib / list-view.js View on Github external
/* using a reversed loop for efficiency */
                    for (let i = checkEnd; i >= checkStart; i--) {
                        fastdom.measure(() => {
                            if (skip) {
                                Vue.set(visibility, i, false);
                            } else if (els[i]) {
                                checkElem(i);
                                if (i < checkEnd && !visibility[i] && visibility[i + 1]) skip = true;
                            }
                        });
                    }
                } else {
                    /* If scrolling down, we only need to check visible items plus those after them */
                    if (direction == DIRECTION_DOWN) checkStart = visibility.indexOf(true);
                    for (let i = checkStart; i <= checkEnd; i++) {
                        fastdom.measure(() => {
                            if (skip) {
                                Vue.set(visibility, i, false);
                            } else if (els[i]) {
                                checkElem(i);
                                if (i > checkStart && !visibility[i] && visibility[i - 1]) skip = true;
                            }
                        });
                    }
                }

                function checkElem(i) {
                    var top = els[i].offsetTop - scrollTop;
                    var bottom = top + placeholders[i];
                    visibility[i] = bottom > -preloadHeight && top < preloadHeight;
                }
            }
github zetter / react-crossword / src / javascripts / crosswords / crossword.js View on Github external
fastdom.read(() => {
        // Our grid is a square, set the height of the grid wrapper
        // to the width of the grid wrapper
        fastdom.write(() => {
          this.$gridWrapper.css(
            'height',
            `${this.$gridWrapper.offset().width}px`,
          );
        });
        this.gridHeightIsSet = true;
      });
    } else if (this.gridHeightIsSet) {
github zetter / react-crossword / src / javascripts / crosswords / crossword.js View on Github external
setGridHeight() {
    if (!this.$gridWrapper) {
      this.$gridWrapper = $(findDOMNode(this.gridWrapper));
    }

    if (
      isBreakpoint({
        max: 'tablet',
      })
    ) {
      fastdom.read(() => {
        // Our grid is a square, set the height of the grid wrapper
        // to the width of the grid wrapper
        fastdom.write(() => {
          this.$gridWrapper.css(
            'height',
            `${this.$gridWrapper.offset().width}px`,
          );
        });
        this.gridHeightIsSet = true;
      });
    } else if (this.gridHeightIsSet) {
      // Remove inline style if tablet and wider
      this.$gridWrapper.attr('style', '');
    }
  }
github orangemug / instantiable-fastdom / test / index.js View on Github external
beforeEach(function() {
    this.origFastdom = new fastdom.constructor;
    this.fastdom = new Fastdom(this.origFastdom);
  });
github salesforce-ux / design-system / site / assets / scripts / shared / tabs.js View on Github external
const runTabClick = (tab, otherTabs) => {
  fastdom.mutate(() => {
    forEach(otherTabs, removeActive);
    addActive(tab);
    emitter.emit('tab:select', { tab, panel: getPanel(tab) });
  });
};
github bmcmahen / cast / index.js View on Github external
Cast.prototype.renderNew = function(block){
  this.emit('render', block)
  fastdom.write(function(){
    this.el.appendChild(block.el);
  }.bind(this));
  fastdom.defer(block.show.bind(block));
};

fastdom

Eliminates layout thrashing by batching DOM read/write operations

MIT
Latest version published 1 month ago

Package Health Score

80 / 100
Full package analysis

Similar packages