當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Immutable.Map類代碼示例

本文整理匯總了TypeScript中Immutable.Map的典型用法代碼示例。如果您正苦於以下問題:TypeScript Map類的具體用法?TypeScript Map怎麽用?TypeScript Map使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Map類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: stations

export function stations(state:Map<string,any> = Map<string,any>(), action:any):Map<string, List<StationModel>> {

    function indexOfStation(businessId, stationId):any {
        return stations.findIndex((i:StationModel) => {
            return i.getKey('businessId') === businessId && i.getKey('id') == stationId;
        });
    }

    switch (action.type) {
        case StationsAction.RECEIVE_STATIONS:
            return state.update(action.source, (value) => action.stations);

        case StationsAction.RECEIVE_STATIONS_GEO:
            for (var i in action.payload) {
                var station = action.payload[i];
                var source = station.source;
                var stations:List<StationModel> = state.get(source);
                stations = stations.update(indexOfStation(station.businessId, station.id), (i_station:StationModel) => {
                    return i_station.setKey<StationModel>(StationModel, 'geoLocation', {
                        lat: station.lat,
                        lon: station.lon,
                        city: station.city,
                        country: station.country
                    })
                });
                state = state.setIn([source], stations);
            }
            return state;
        default:
            return state;
    }
}
開發者ID:Floodlight-Studios,項目名稱:studioDashboard,代碼行數:32,代碼來源:StationsReducer.ts

示例2: referencedModels

export function referencedModels(
  project: Project,
  mod: Module,
  all?: Map<string, ModelDef>,
): Map<string, ModelDef> {
  if (!all) {
    all = Map();
  }
  const mdl = defined(project.model(mod.modelName));
  const name = mdl.ident;
  if (all.has(name)) {
    const def = defined(all.get(name)).update('modules', (modules: Set<Module>) =>
      modules.add(mod),
    );
    all = all.set(name, def);
  } else {
    all = all.set(
      name,
      new ModelDef({
        model: mdl,
        modules: Set<Module>([mod]),
      }),
    );
  }
  for (const [name, module] of mdl.modules) {
    all = referencedModels(project, module, all);
  }
  return all;
}
開發者ID:bpowers,項目名稱:sd.js,代碼行數:29,代碼來源:vars.ts

示例3: cadd

    const director = (d: Map<State, Complex>, t: number)=>{
        const result = Map<State, Complex>().asMutable();

        // 量子ゆらぎの定數
        const gt0 = t / STEPS;
        const gt1 = 1 - gt0;
        // const gt = 100 * ((t+1) ** (-1.5)) - 0.1;   // t = 99 で0になる!

        // 方向
        for(let a=0; a<N; a++){
            // 位置
            for(let v=0, n=2**N; v<n; v++){
                // ===== H0
                // Sを適用する前の位置
                const vb = v ^ (1 << a);
                // vbの確率はGrover's diffusion operatorをかけて求める
                let s = czero;
                for(let b=0; b<N; b++){
                    const dd = a===b ? 2/N-1 : 2/N;
                    s = cadd(s, csmul(dd, d.get(makeState(b, vb), czero)));
                }
                s = csmul(gt0, s);

                // ===== H1
                let s2 = czero;
                for(let w=0; w<n; w++){
                    const dd = v===w ? 2/n-1 : 2/n;
                    s2 = cadd(s2, csmul(dd, d.get(makeState(a, w), czero)));
                }
                s = cadd(s, cmul(csmul(gt1, ci), s2));
                result.set(makeState(a, v), s);
            }
        }
        return result.asImmutable();
    };
開發者ID:uhyo,項目名稱:enshu3-quantum,代碼行數:35,代碼來源:annealing.ts

示例4: appdb

export default function appdb(state:Map<string, any> = Map<string, any>({}), action:any):Map<string, any> {
    switch (action.type) {
        case StationsAction.RECEIVE_TOTAL_STATIONS:
            return state.merge({
                totalStations: {time: Date.now(), totalStations: action.totalStations}
            });
        case AppdbAction.AUTH_FAIL:
        case AppdbAction.AUTH_PASS:
            return state.merge({
                credentials: {
                    authenticated: action.authenticated,
                    user: action.user,
                    pass: action.pass,
                    remember: action.remember,
                    reason: action.reason
                },
                appBaseUrlUser: `${baseUrl}?resellerUserName=${action.user}&resellerPassword=${action.pass}`
            });
        case AppdbAction.APP_INIT:
            return state.merge({
                appStartTime: Date.now(),
                appBaseUrl: `${baseUrl}`
            });
        case AppdbAction.CLOUD_SERVERS:
            return state.merge({
                cloudServers: action.payload
            });
        case AppdbAction.SERVERS_STATUS:
            return state.merge({serversStatus: action.payload});
        default:
            return state;
    }
}
開發者ID:Floodlight-Studios,項目名稱:studioDashboard,代碼行數:33,代碼來源:AppdbReducer.ts

示例5: 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

示例6: it

 it('accepts flattened pairs via of()', () => {
   var m: Map<any, any> = Map.of(1, 'a', 2, 'b', 3, 'c');
   expect(m.size).toBe(3);
   expect(m.get(1)).toBe('a');
   expect(m.get(2)).toBe('b');
   expect(m.get(3)).toBe('c');
 });
開發者ID:threehams,項目名稱:immutable-js,代碼行數:7,代碼來源:Map.ts

示例7: updateCanonical

  updateCanonical(callback: Function) {
    let canonical = this.cacheMap.get('canonical');
    let localData = this.cacheMap.get('local');

    let newCanonical = callback.call(null, canonical, localData);

    this.cacheMap = this.cacheMap.set(CANONICAL, newCanonical);
  }
開發者ID:fivetanley,項目名稱:diamond,代碼行數:8,代碼來源:diamond.ts

示例8:

 disks.filter((disk) =>  disk.get('online') && (
                             (
                                 !this.isDiskUsed(disk, diskUsage.get('attached')) &&
                                 !this.isDiskUsed(disk, diskUsage.get('boot')) &&
                                 !this.isDiskUsed(disk, diskUsage.get('reserved'))
                             ) || this.isDiskUsed(disk, diskUsage.get('freed'))
                         )
開發者ID:mactanxin,項目名稱:gui,代碼行數:7,代碼來源:disk-repository.ts

示例9: binary

  binary(n: ast.BinaryExpr): string {
    // exponentiation isn't a builtin operator in JS, it
    // is implemented as a function in the Math module.
    if (n.op === '^') {
      const l = n.l.walk(this);
      const r = n.r.walk(this);
      return `Math.pow(${l}, ${r})`;
    } else if (n.op === '=' && n.l instanceof ast.Constant && isNaN(n.l.value)) {
      const r = n.r.walk(this);
      return `isNaN(${r})`;
    } else if (n.op === '=' && n.r instanceof ast.Constant && isNaN(n.r.value)) {
      const l = n.r.walk(this);
      return `isNaN(${l})`;
    }

    let op = n.op;
    // only need to convert some of them
    if (JsOps.has(n.op)) {
      op = defined(JsOps.get(n.op));
    }

    const l = n.l.walk(this);
    const r = n.r.walk(this);
    return `${l} ${op} ${r}`;
  }
開發者ID:bpowers,項目名稱:sd.js,代碼行數:25,代碼來源:vars.ts

示例10: Graph

    addNode(node: any) {
        var nodes = this.nodes.push(node);
        var children = this.children.set(node.id, List<any>());
        var parents = this.parents.set(node.id, List<any>());

        return new Graph(nodes, children, parents);
    }
開發者ID:gsanta,項目名稱:gsgraph,代碼行數:7,代碼來源:Graph.ts


注:本文中的Immutable.Map類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。