How to use the underscore.findWhere function in underscore

To help you get started, we’ve selected a few underscore 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 amtrack / force-dev-tool / lib / metadata-container.js View on Github external
}
			var type = component.getMetadataType();
			if (!type) {
				throw new Error('Could not determine type for filename ' + componentFileName);
			}
			// 1. container files
			if (metadataFile instanceof MetadataFileContainer) {
				// get all components with same fileName
				var relatedComponents = _.where(manifest.manifestJSON, {
					fileName: componentFileName
				});
				var containerComponent = _.where(relatedComponents, {
					type: type.xmlName,
					fullName: component.fullName
				});
				var vinylContainer = _.findWhere(self.vinyls, {
					path: componentFileName
				});
				if (containerComponent && containerComponent.length) {
					// container itself is being referenced in manifest
					filteredMetadataContainer.add(vinylContainer, []);
				} else {
					// construct a new File containing only related components
					var containerFile = new MetadataFileContainer({
						path: componentFileName
					});
					relatedComponents.forEach(function(cmp) {
						var c = _.findWhere(vinylContainer.components, {
							type: cmp.type,
							fullName: cmp.fullName
						});
						if (!c) {
github catarse / catarse.js / src / vms / reward-vm.js View on Github external
mapStates = _.map(states(), (state) => {
            let fee;
            const feeState = _.findWhere(fees(), {
                destination: state.acronym
            });
            const feeOthers = _.findWhere(fees(), {
                destination: 'others'
            });
            if (feeState) {
                fee = feeState.value;
            } else if (feeOthers) {
                fee = feeOthers.value;
            }

            return {
                name: state.name,
                value: state.acronym,
                fee
            };
        });
    if (reward.shipping_options === 'national') {
github mozilla / learning.mozilla.org / pages / clubs / About.jsx View on Github external
handleClubEdit: function(url) {
    var club = _.findWhere(this.props.teachAPI.getClubs(), {
      url: url
    });

    this.props.showModal(ModalAddOrChangeYourClub, {
      club: club,
      onSuccess: this.handleZoomToClub,
      hideModal: this.props.hideModal
    });
  },
  render: function() {
github OpenUserJS / OpenUserJS.org / controllers / user.js View on Github external
_.map(options.commentList, function (aComment) {
        if (aComment._discussionId) {
          aComment.discussion = modelParser.parseDiscussion(aComment._discussionId);

          var category = _.findWhere(categories, { slug: aComment.discussion.category });
          if (!category) {
            category = modelParser.parseCategoryUnknown(aComment.discussion.category);
          }
          aComment.category = modelParser.parseCategory(category);

          if (aComment.discussion.issue) {
            aComment.script = {
              scriptPageUrl: aComment.category.categoryPageUrl.replace('/issues', ''),
              name: category.name
            };
            category.name = 'Issues';
          } else {
            aComment.script = {
              scriptPageUrl: '/forum',
              name: 'Forum'
            };
github CartoDB / deep-insights.js / src / widgets / time-series / content-view.js View on Github external
_calculateBars: function () {
    var data = this._dataviewModel.getData();
    var min = this.model.get('min');
    var max = this.model.get('max');
    var loBarIndex = this.model.get('lo_index');
    var hiBarIndex = this.model.get('hi_index');
    var startMin;
    var startMax;

    if (data.length > 0) {
      if (!_.isNumber(min) && !_.isNumber(loBarIndex)) {
        loBarIndex = 0;
      } else if (_.isNumber(min) && !_.isNumber(loBarIndex)) {
        startMin = _.findWhere(data, {start: min});
        loBarIndex = startMin && startMin.bin || 0;
      }

      if (!_.isNumber(max) && !_.isNumber(hiBarIndex)) {
        hiBarIndex = data.length;
      } else if (_.isNumber(max) && !_.isNumber(hiBarIndex)) {
        startMax = _.findWhere(data, {end: max});
        hiBarIndex = startMax && startMax.bin + 1 || data.length;
      }
    } else {
      loBarIndex = 0;
      hiBarIndex = data.length;
    }

    return {
      loBarIndex: loBarIndex,
github catarse / catarse.js / src / root / projects-subscription-report.js View on Github external
view: function(ctrl, args) {
        const subsCollection = ctrl.subscriptions.collection(),
            filterBuilder = ctrl.filterBuilder,
            statusFilter = _.findWhere(filterBuilder, {
                label: 'status_filter'
            }),
            textFilter = _.findWhere(filterBuilder, {
                label: 'text_filter'
            }),
            rewardFilter = _.findWhere(filterBuilder, {
                label: 'reward_filter'
            }),
            paymentFilter = _.findWhere(filterBuilder, {
                label: 'payment_filter'
            });
        rewardFilter.data.options = ctrl.mapRewardsToOptions();
        if (!ctrl.lProject()) {
            return m('div', [
                m.component(projectDashboardMenu, {
                    project: m.prop(_.first(ctrl.project()))
                }),
                m('.dashboard-header',
                    m('.w-container',
github coveo / react-vapor / packages / react-vapor / src / components / navigation / perPage / NavigationPerPageConnected.tsx View on Github external
const mapStateToProps = (
    state: IReactVaporState,
    ownProps: INavigationPerPageOwnProps
): INavigationPerPageStateProps => {
    const perPageNumber: number[] = ownProps.perPageNumbers || PER_PAGE_NUMBERS;
    const defaultInitialPosition: number = Math.ceil(perPageNumber.length / 2) - 1;
    const item: IPerPageState = _.findWhere(state.perPageComposite, {id: ownProps.id});
    const pagination: IPaginationState = _.findWhere(state.paginationComposite, {id: `pagination-${ownProps.id}`});
    const initialPosition: number = !_.isUndefined(ownProps.initialPosition)
        ? ownProps.initialPosition
        : defaultInitialPosition;

    return {
        currentPerPage: item ? item.perPage : perPageNumber[initialPosition],
        currentPage: pagination ? pagination.pageNb : 0,
    };
};
github raycmorgan / sqlbox / lib / model_methods.js View on Github external
function columnByName(model, columnName) {
  return _.findWhere(model.columns, {name: columnName});
}
github CleverStack / clever-orm / bin / seedModels.js View on Github external
function associateModel(data, modelCb) {
                if (data.associations !== undefined) {
                  var assocLength = Object.keys(data.associations).length
                    , called      = 0
                    , model       = _.findWhere(assocMap[modelName], { id: data.id });

                  Object.keys(data.associations).forEach(function(assocModelName) {
                    var required     = data.associations[assocModelName]
                      , associations = [];

                    if (!(required instanceof Array)) {
                      required = [required];
                    }

                    required.forEach(function(requiredModels) {
                      if (!(requiredModels instanceof Array)) {
                        requiredModels = [requiredModels];
                      }
                      
                      requiredModels.forEach(function(requiredModel) {
                        var associatedModel;
github humanmade / feelingrestful-theme / js / reducers.js View on Github external
case 'UPDATE_POINTS_OF_INTEREST':
			state.pointsOfInterest = action.pointsOfInterest
			break
		case 'UPDATE_POSTS':
			state.posts = action.posts
			break
		case 'UPDATE_POST':
			if ( ! findWhere( state.posts, {id: action.post.id} ) ) {
				state.posts.push( action.post );
			}
			break;
		case 'UPDATE_PAGES':
			state.pages = action.pages
			break
		case 'UPDATE_PAGE':
			if ( ! findWhere( state.pages, {id: action.page.id} ) ) {
				state.pages.push( action.page );
			}
			break;
	}
	return state
}