当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Map.getIn方法代码示例

本文整理汇总了TypeScript中Immutable.Map.getIn方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Map.getIn方法的具体用法?TypeScript Map.getIn怎么用?TypeScript Map.getIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Immutable.Map的用法示例。


在下文中一共展示了Map.getIn方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: adnet

export function adnet(state: Map<string,any> = Map<string,any>(), action: any): Map<string,any> {

    var indexOfRateId = function (i_rateId: string) {
        return rates.findIndex((i: AdnetRateModel) => i.rateId() === i_rateId);
    }
    var indexOfCustomerId = function (i_adnetCustomerId: string) {
        return customers.findIndex((i: AdnetCustomerModel) => i.customerId() === i_adnetCustomerId);
    }
    switch (action.type) {
        case AdnetActions.RECEIVE_CUSTOMERS: {
            return state.setIn(['customers'], action.customers);
        }
        case AdnetActions.RECEIVE_RATES: {
            return state.setIn(['rates'], action.rates);
        }
        case AdnetActions.UPDATE_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);

            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                return rate.setField('rateMap', action.payload.rateTable)
            });
            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                rate = rate.setField('hourRate0', action.payload.adHourlyRate["0"])
                rate = rate.setField('hourRate1', action.payload.adHourlyRate["1"])
                rate = rate.setField('hourRate2', action.payload.adHourlyRate["2"])
                rate = rate.setField('hourRate3', action.payload.adHourlyRate["3"])
                return rate;
            });
            return state.setIn(['rates'], rates);
        }
        case AdnetActions.ADD_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            rates = rates.push(action.adnetRateModel);
            return state.setIn(['rates'], rates);
        }
        case AdnetActions.REMOVE_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            var updatedRates:List<AdnetRateModel> = rates.filter((adnetRateModel:AdnetRateModel) => adnetRateModel.rateId() !== action.rateId) as List<AdnetRateModel>;
            return state.setIn(['rates'], updatedRates);
        }
        case AdnetActions.UPDATE_ADNET_CUSTOMER: {
            var customers: List<AdnetCustomerModel> = state.getIn(['customers'])
            customers = customers.update(indexOfCustomerId(action.payload.Key), (customer: AdnetCustomerModel) => {
                return customer.setData<AdnetCustomerModel>(AdnetCustomerModel, action.payload)
            });
            return state.setIn(['customers'], customers);
        }
        case AdnetActions.RENAME_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                return rate.setField('label', action.payload.newLabel)
            });
            return state.setIn(['rates'], rates);
        }
        default:
            return state;
    }
}
开发者ID:nubiofs,项目名称:studioDashboard,代码行数:58,代码来源:AdnetReducer.ts

示例2: to3

 3: function to3(nb : Map<string, any>) {
   return nb
     .setIn(['metadata', 'orig_nbformat'], nb.getIn(['metadata', 'orig_nbformat'], 2))
     .set('nbformat', 3)
     .set('nbformat_minor', 0)
     .setIn(['worksheets', 'cels'], nb
       .getIn(['worksheets', 0, 'cells'])
       .map(cell => {
         const newCell = cell.set('metadata', Map<string, any>());
         return newCell;
       })
     );
 },
开发者ID:jdetle,项目名称:commutable,代码行数:13,代码来源:convert.ts

示例3: transform

  /**
   * Brief format for references
   */
  transform(item: Map<string, any>): string {
    let referenceHTML = '';
    let hasRefUrl = false;
    let title = '';
    let author = '';
    let arxivEprint = '';
    let label = '';
    let pubNote = '';
    let reportNumber = '';
    let misc = '';

    hasRefUrl = item.hasIn(['record', '$ref']);

    item = item.get('reference');

    if (!item) {
      return referenceHTML;
    }

    arxivEprint = item.get('arxiv_eprint', '');
    reportNumber = item.getIn(['report_numbers', 0], '');
    if (item.has('label')) {
      label = `[${item.get('label')}] `;
    }

    if (item.has('titles')) {
      title = item.getIn(['titles', 0, 'title'], '');
    }
    if (item.has('authors')) {
      author = item.getIn(['authors', 0, 'full_name'], '') + ' ';
      if (item.get('authors').size > 1) {
        author += 'el al. ';
      }
    }
    if (item.has('publication_info')) {
      pubNote += item.getIn(['publication_info', 'journal_title'], '') + ' ';
      pubNote += item.getIn(['publication_info', 'journal_volume'], '') + ' ';
      pubNote += '(' + item.getIn(['publication_info', 'year'], '') + ') ';
      pubNote += item.getIn(['publication_info', 'artid'], '') + ' ';
    }
    if (!author) {
      if (item.has('collaborations')) {
        author = item.getIn(['collaborations', 0]) + ' ';
      }
    }

    if (!hasRefUrl) {
      misc = item.getIn(['misc', 0], '');
    }

    referenceHTML = label + title + author + pubNote + arxivEprint + reportNumber + misc;

    return referenceHTML;

  }
开发者ID:inspirehep,项目名称:record-editor,代码行数:58,代码来源:reference-brief.ts

示例4: reducer

function reducer(state: IReduxState = initial, { type, payload }: IAction): IReduxState {
  const imState: Map<string, any> = fromJS(state);
  switch (type) {
  case 'VIEW_POLLS:LOAD_POLLS_SUCCESS':
    return imState.set('polls', payload).toJS();
  case 'VIEW_POLLS:LOAD_POLL_SUCCESS': {
    interface IData { results: IPollResult[]; poll: IPoll; }
    const data = payload as IData;
    return imState.set('selectedPoll', data).toJS();
  }
  case 'VIEW_POLLS:SELECT_ANSWER': {
    interface IData { questionIndex: number; answerIndex: number; }
    const data = payload as IData;
    const questions = imState.getIn(['selectedPoll', 'poll', 'questions']);
    const question = questions.get(data.questionIndex);

    return imState.setIn(
      ['selectedPoll', 'poll', 'questions', data.questionIndex],
      question.set('answers', question.get('answers').map(
          (answer: Map<string, any>, index: number) => answer.set('isSelected', index === data.answerIndex),
      )),
    ).toJS();
  }
  default: return state;
  }
}
开发者ID:sigrlami,项目名称:pollock,代码行数:26,代码来源:reducer.ts

示例5:

 _.forEach(action.payload, (v, k)=> {
     var type = k.split('_')[0]
     var key = k.split('_')[1]
     var value = v;
     var accountModels:List<AccountModel> = state.getIn(['accounts']);
     var index = accountModels.findIndex((i:AccountModel) => i.getType().toLowerCase() === type.toLowerCase());
     if (index == -1)
         return state;
     accountModels = accountModels.update(index, (accountModel:AccountModel) => {
         return accountModel.setKey<AccountModel>(AccountModel, key, value);
     });
     state = state.setIn(['accounts'], accountModels);
 });
开发者ID:alexbraisch,项目名称:studioDashboard,代码行数:13,代码来源:ResellerReducer.ts

示例6:

 (cells: Map<CellId, ImmutableCell>) =>
   cells.setIn(
     [id, "metadata", "outputExpanded"],
     !cells.getIn([id, "metadata", "outputExpanded"])
   )
开发者ID:nteract,项目名称:nteract,代码行数:5,代码来源:notebook.ts

示例7: reducer

function reducer(state: IReduxState = initial, { type, payload }: IAction): IReduxState {
  const imState: Map<string, any> = fromJS(state);

  switch (type) {
  case 'CREATE_POLL:CHANGE_FIELD_VALUE': {
    interface IData { fieldName: string; fieldValue: string; }
    const data: IData = payload as IData;
    return imState
      .setIn(['newPoll', data.fieldName], data.fieldValue)
      .toJS();
  }
  case 'CREATE_POLL:ADD_ANSWER': {
    const index: number = payload as number;
    const questions: List<Map<string, any>> = imState.getIn(['newPoll', 'questions']);
    const question: Map<string, any> = questions.get(index);

    return imState
      .setIn(
        ['newPoll', 'questions'],
        questions.set(index, question.set('answers', question.get('answers').push(initialAnswer))),
      ).toJS();
  }
  case 'CREATE_POLL:ADD_QUESTION': {
    return imState.setIn(
      ['newPoll', 'questions'],
      (imState.getIn(['newPoll', 'questions']) as List<IEditableQuestion>).push(initialQuestion),
    ).toJS();
  }
  case 'CREATE_POLL:CHANGE_ANSWER_TEXT': {
    interface IData { questionIndex: number; answerIndex: number; value: string; }
    const data: IData = payload as IData;
    const questions = imState.getIn(['newPoll', 'questions']);
    const question = questions.get(data.questionIndex);
    const answers = question.get('answers');
    const answer = answers.get(data.answerIndex);

    return imState.withMutations((mutable: Map<string, any>) => mutable.setIn(
      ['newPoll', 'questions'],
      questions.set(
        data.questionIndex,
        question.set('answers', answers.set(data.answerIndex, answer.set('text', data.value))),
      ),
    )).toJS();
  }
  case 'CREATE_POLL:CHANGE_QUESTION_FIELD': {
    interface IData { questionIndex: number; value: string; fieldName: string; }
    const data = payload as IData;
    const questions = imState.getIn(['newPoll', 'questions']);
    return imState.setIn(
      ['newPoll', 'questions'],
      questions.set(
        data.questionIndex,
        questions.get(data.questionIndex).set(data.fieldName, data.value),
      ),
    ).toJS();
  }
  case 'CREATE_POLL:SEND_NEW_POLL_SUCCESS':
    return imState.set('newPoll', initial.newPoll).toJS();
  case 'CREATE_POLL:LOAD_POLL_SUCCESS':
    return imState.set('newPoll', payload).toJS();
  case 'CREATE_POLL:CLEAR_DATA':
    return imState.set('newPoll', initial.newPoll).toJS();
  default:
    return state;
  }
}
开发者ID:sigrlami,项目名称:pollock,代码行数:66,代码来源:reducer.ts

示例8: switch


//.........这里部分代码省略.........
                    type: "directory",
                    // The listing is all these contents in aggregate
                    items: sorted
                  }),
                  filepath: fetchContentFulfilledAction.payload.filepath,
                  lastSaved:
                    fetchContentFulfilledAction.payload.model.last_modified,
                  created: fetchContentFulfilledAction.payload.model.created,
                  loading: false,
                  saving: false,
                  error: null
                })
              )
          );
        }
        case "notebook": {
          const immutableNotebook = fromJS(
            fetchContentFulfilledAction.payload.model.content
          );

          return state.set(
            fetchContentFulfilledAction.payload.contentRef,
            makeNotebookContentRecord({
              created: fetchContentFulfilledAction.payload.created,
              lastSaved: fetchContentFulfilledAction.payload.lastSaved,
              filepath: fetchContentFulfilledAction.payload.filepath,
              model: makeDocumentRecord({
                notebook: immutableNotebook,
                savedNotebook: immutableNotebook,
                transient: Map({
                  keyPathsForDisplays: Map(),
                  cellMap: Map()
                }),
                cellFocused: immutableNotebook.getIn(["cellOrder", 0])
              }),
              loading: false,
              saving: false,
              error: null
            })
          );
        }
      }

      // NOTE: There are no other content types (at the moment), so we will just
      //       warn and return the current state
      console.warn("Met some content type we don't support");
      return state;
    case actionTypes.CHANGE_FILENAME: {
      const changeFilenameAction = action as actionTypes.ChangeFilenameAction;
      return state.updateIn(
        [changeFilenameAction.payload.contentRef],
        contentRecord =>
          contentRecord.merge({
            filepath: changeFilenameAction.payload.filepath
          })
      );
    }
    case actionTypes.SAVE_FULFILLED: {
      const saveFulfilledAction = action as actionTypes.SaveFulfilled;
      return state
        .updateIn(
          [saveFulfilledAction.payload.contentRef, "model"],
          (model: ContentModel) => {
            // Notebook ends up needing this because we store a last
            // saved version of the notebook Alternatively, we could
            // be storing a hash of the content to compare 🤔
开发者ID:nteract,项目名称:nteract,代码行数:67,代码来源:index.ts

示例9: reseller

export function reseller(state:Map<string,any> = Map<string,any>(), action:any):Map<string,any> {

    switch (action.type) {
        case ResellerAction.RECEIVE_APPS:
        {
            return state.setIn(['apps'], action.apps);
        }
        case ResellerAction.UPDATE_APP:
        {
            var appModels:List<AppModel> = state.getIn(['apps']);
            var index = appModels.findIndex((i:AppModel) => i.getAppId() === action.app.getAppId());
            appModels = appModels.update(index, (appModel:AppModel) => {
                return appModel.setKey<AppModel>(AppModel, 'installed', action.mode)
            });
            return state.setIn(['apps'], appModels);
        }
        case ResellerAction.RECEIVE_WHITELABEL:
        {
            return state.setIn(['whitelabel'], action.whitelabelModel);
        }
        case ResellerAction.RECEIVE_ACCOUNT_INFO:
        {
            return state.setIn(['accounts'], action.accountModels);
        }
        case ResellerAction.UPDATE_DEFAULT_PRIVILEGE:
        {
            return state.setIn(['privilegeDefault'], action.privilegeId);
        }
        case ResellerAction.RECEIVE_DEFAULT_PRIVILEGE:
        {
            return state.setIn(['privilegeDefault'], action.privilegeId);
        }
        case ResellerAction.RECEIVE_PRIVILEGES:
        {
            return state.setIn(['privileges'], action.privilegesModels);
        }
        case ResellerAction.RECEIVE_PRIVILEGES_SYSTEM:
        {
            return state.setIn(['privilegesSystem'], action.privelegesSystemModels);
        }
        // case ResellerAction.RECEIVE_SERVER_SOURCES:
        // {
        //     return state.setIn(['serverSources'], action.sourceModels);
        // }
        case ResellerAction.UPDATE_PRIVILEGE_NAME:
        {
            var privileges = state.get('privileges');
            privileges.forEach((i_privelegesModel:PrivelegesModel, counter)=> {
                if (i_privelegesModel.getPrivelegesId() == action.privilegeId) {
                    var updPriv = i_privelegesModel.setKey(PrivelegesModel, 'name', action.privilegeName)
                    privileges = privileges.set(counter, updPriv);
                }
            })
            return state.setIn(['privileges'], privileges);
        }
        case ResellerAction.ADD_PRIVILEGE:
        {
            var privileges = state.get('privileges');
            var updatedPrivelegesModels:List<PrivelegesModel> = privileges.push(action.privelegesModel);
            return state.setIn(['privileges'], updatedPrivelegesModels);
        }
        case ResellerAction.REMOVE_PRIVILEGE:
        {
            var privileges = state.get('privileges');
            var updatedPrivelegesModels:List<PrivelegesModel> = privileges.filter((privelegesModel:PrivelegesModel) => privelegesModel.getPrivelegesId() !== action.privilegeId) as List<PrivelegesModel>;
            return state.setIn(['privileges'], updatedPrivelegesModels);
        }
        case ResellerAction.UPDATE_PRIVILEGE_ATTRIBUTE:
        {
            var privileges = state.get('privileges');
            privileges.forEach((i_privelegesModel:PrivelegesModel, counter)=> {
                if (i_privelegesModel.getPrivelegesId() == action.payload.privelegesId) {
                    i_privelegesModel.getColumns().forEach((group, c) => {
                        if (group.get('tableName') == action.payload.tableName) {
                            var value = Lib.BooleanToNumber(action.payload.value);
                            var path = ['groups', c, action.payload.privelegesAttribute];
                            var data = i_privelegesModel.getData().updateIn(path, v => value)
                            var updPriv = i_privelegesModel.setData<PrivelegesModel>(PrivelegesModel, data);
                            privileges = privileges.set(counter, updPriv);
                        }
                    })
                }
            })
            return state.setIn(['privileges'], privileges);
        }
        case ResellerAction.UPDATE_PRIVILEGES:
        {
            var privileges = state.get('privileges');
            privileges.forEach((i_privelegesModel:PrivelegesModel, counter)=> {
                if (i_privelegesModel.getPrivelegesId() == action.payload.privelegesId) {
                    i_privelegesModel.getColumns().forEach((group, c) => {
                        if (group.get('tableName') == action.payload.tableName) {
                            var key = Lib.MapOfIndex(group.get('columns'), action.payload.index, 'first');
                            var path = ['groups', c, 'columns', key];
                            var data = i_privelegesModel.getData().updateIn(path, v => action.payload.updTotalBits)
                            var updPriv = i_privelegesModel.setData<PrivelegesModel>(PrivelegesModel, data);
                            privileges = privileges.set(counter, updPriv);
                        }
                    })
                }
//.........这里部分代码省略.........
开发者ID:alexbraisch,项目名称:studioDashboard,代码行数:101,代码来源:ResellerReducer.ts

示例10: business

export function business(state:Map<string,any> = Map<string,any>(), action:any):Map<string,any> {

    function indexOfName(businessId, name):any {
        return businessUsers.findIndex((i:BusinessUser) => {
            return i.getBusinessId() === businessId && i.getKey('name') == name;
        });
    }

    switch (action.type) {
        case BusinessAction.REQUEST_BUSINESSES:
            return state;

        case BusinessAction.RECEIVE_BUSINESSES:
            var businesses:List<BusinessModel> = state.getIn(['businesses'])
            var list:List<BusinessModel> = businessesReducer(businesses, action);
            return state.setIn(['businesses'], list);

        case BusinessAction.RECEIVE_BUSINESS_USER:
            return state.setIn(['businessUsers'], action.businessUsers);

        case BusinessAction.RECEIVE_BUSINESSES_SOURCES:
            return state.setIn(['businessSources'], action.businessSources);

        case BusinessAction.RECEIVE_BUSINESS_SAMPLES:
            return state.setIn(['samples'], action.sampleModels);

        case BusinessAction.RECEIVE_BUSINESSES_STATS:
            return state.setIn(['businessStats'], action.stats);

        case BusinessAction.SET_BUSINESS_DATA:
            var businesses:List<BusinessModel> = state.getIn(['businesses'])
            var list:List<BusinessModel> = businessesReducer(businesses, action);
            return state.setIn(['businesses'], list);

        case BusinessAction.SET_BUSINESS_ACCOUNT_DATA:
        {
            var businesses:List<BusinessModel> = state.getIn(['businesses'])
            var indexOfBusiness = function(businessId:string) {
                return businesses.findIndex((i:BusinessModel) => i.getBusinessId() === businessId);
            }
            businesses = businesses.update(indexOfBusiness(action.payload.businessId), (business:BusinessModel) => {
                var updBusiness:BusinessModel = business.setKey<BusinessModel>(BusinessModel, 'name', action.payload.name)
                updBusiness = updBusiness.setKey<BusinessModel>(BusinessModel, 'allowSharing', action.payload.allowSharing)
                return updBusiness.setKey<BusinessModel>(BusinessModel, 'maxMonitors', action.payload.maxMonitors)
            });
            return state.setIn(['businesses'], businesses);
        }

        case BusinessAction.CHANGE_BUSINESS_USER_NAME:
        {
            var businessUsers:List<BusinessUser> = state.getIn(['businessUsers'])
            // new name is already taken or user ended up not modifying original name, ignore
            if (indexOfName(action.businessId, action.value.newValue) != -1)
                return state;
            businessUsers = businessUsers.update(indexOfName(action.businessId, action.value.oldValue), (business:BusinessUser) => {
                return business.setKey<BusinessUser>(BusinessUser, action.key, action.value.newValue)
            });
            return state.setIn(['businessUsers'], businessUsers);
        }

        case BusinessAction.SET_BUSINESS_USER_ACCESS:
        {
            var businessUsers:List<BusinessUser> = state.getIn(['businessUsers'])
            businessUsers = businessUsers.update(indexOfName(action.payload.businessId, action.payload.name), (business:BusinessUser) => {
                let businessUser:BusinessUser = business.setKey<BusinessUser>(BusinessUser, 'accessMask', action.payload.accessMask)
                return businessUser.setKey<BusinessUser>(BusinessUser, 'privilegeId', action.payload.privilegeId)
            });
            return state.setIn(['businessUsers'], businessUsers);
        }

        case BusinessAction.ADD_BUSINESS_USER:
        {
            var businessUsers:List<BusinessUser> = state.getIn(['businessUsers'])
            businessUsers = businessUsers.push(action.BusinessUser);
            return state.setIn(['businessUsers'], businessUsers);
        }

        case BusinessAction.REMOVE_BUSINESS:
        {
            var businesses:List<BusinessModel> = state.getIn(['businesses'])
            var updatedBusinesses:List<BusinessModel> = businesses.filter((businessModel:BusinessModel) => businessModel.getBusinessId() !== action.businessId) as List<BusinessModel>;
            return state.setIn(['businesses'], updatedBusinesses);
        }

        case BusinessAction.REMOVE_BUSINESS_USER:
        {
            var businessUsers:List<BusinessUser> = state.getIn(['businessUsers'])
            var updatedBusinessUsers:List<BusinessUser> = businessUsers.filter((businessUser:BusinessUser) => businessUser.getName() !== action.BusinessUser.getName()) as List<BusinessUser>;
            return state.setIn(['businessUsers'], updatedBusinessUsers);
        }

        default:
            return state;
    }
}
开发者ID:amurarnd,项目名称:studioDashboard,代码行数:95,代码来源:BusinessReducer.ts


注:本文中的Immutable.Map.getIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。