Example #1
0
/**
 * @name map
 * @method
 * @private
 * @memberof Frampton.Signal.Signal#
 * @param {*} mapping - A function or value to map the signal with. If a function, the value
 *                        on the parent signal will be passed to the function and the signal will
 *                        be mapped to the return value of the function. If a value, the value of
 *                        the parent signal will be replaced with the value.
 * @returns {Frampton.Signal.Signal} A new signal with mapped values
 */
function map(mapping) {
  const parent = this;
  const mappingFn = isFunction(mapping) ? mapping : ofValue(mapping);
  const initial = (parent._hasValue) ? mappingFn(parent._value) : undefined;
  return createSignal((self) => {
    self.push(mappingFn(parent._value));
  }, [parent], initial);
}
Example #2
0
/**
 * Remove values from the Signal based on the given predicate function. If a function is not
 * given then filter will use strict equals with the value given to test new values on the
 * Signal.
 *
 * @name filter
 * @method
 * @private
 * @memberof Frampton.Signal.Signal#
 * @param {*} predicate - Usually a function to test values of the Signal
 * @returns {Frampton.Signal.Signal}
 */
function filter(predicate) {
  const parent = this;
  const filterFn = isFunction(predicate) ? predicate : isEqual(predicate);
  const initial = (parent._hasValue && filterFn(parent._value)) ? parent._value : undefined;
  return createSignal((self) => {
    if (filterFn(parent._value)) {
      self.push(parent._value);
    }
  }, [parent], initial);
}
Example #3
0
export default curry((parent, child) => {
  if (parent === child) {
    return true;
  } else if (isFunction(parent.contains)) {
    return parent.contains(child);
  } else {
    while (child = child.parentNode) {
      if (parent === child) {
        return true;
      }
      return false;
    }
  }
});