<commit_before>import {Subscriber} from 'rxjs/Rx';
import {ObservableCursor} from './observable-cursor';
import * as _ from 'lodash';

const COLLECTION_EVENTS_DEBOUNCE_TIMEFRAME = 100;

export function toObservable<T>(cursor : Mongo.Cursor<T>) : ObservableCursor<Array<T>> {
  const observable =
      ObservableCursor.create((observer : Subscriber<Array<T>>) => {
    const rawHandleChange = () => Zone.current.run(() => observer.next(cursor.fetch()));
    const handleChange = _.throttle(
      rawHandleChange,
      COLLECTION_EVENTS_DEBOUNCE_TIMEFRAME,
      {trailing: true});

    let handler;
    let isReactive = observable.isReactive();
    observable._cursorRef = cursor;
    observable._reloadRef = handleChange;

    if (isReactive) {
      handler = cursor.observe({
        added: handleChange,
        changed: handleChange,
        removed: handleChange
      });<commit_msg>chore(observable): Decreased the throttle time to 16ms (60fps)<commit_after>import {Subscriber} from 'rxjs/Rx';
import {ObservableCursor} from './observable-cursor';
import * as _ from 'lodash';

const COLLECTION_EVENTS_DEBOUNCE_TIMEFRAME = 16;

export function toObservable<T>(cursor : Mongo.Cursor<T>) : ObservableCursor<Array<T>> {
  const observable =
      ObservableCursor.create((observer : Subscriber<Array<T>>) => {
    const rawHandleChange = () => Zone.current.run(() => observer.next(cursor.fetch()));
    const handleChange = _.throttle(
      rawHandleChange,
      COLLECTION_EVENTS_DEBOUNCE_TIMEFRAME,
      {trailing: true});

    let handler;
    let isReactive = observable.isReactive();
    observable._cursorRef = cursor;
    observable._reloadRef = handleChange;

    if (isReactive) {
      handler = cursor.observe({
        added: handleChange,
        changed: handleChange,
        removed: handleChange
      });
{'fraction_non_alphanumeric': 0.1195414847161572, 'fraction_numerical': 0.0049126637554585155, 'mean_word_length': 3.9010695187165774, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6192975', 'n_tokens_mistral': 566, 'n_tokens_neox': 543, 'n_words': 115}