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


TypeScript immuts.makeImmutable函数代码示例

本文整理汇总了TypeScript中immuts.makeImmutable函数的典型用法代码示例。如果您正苦于以下问题:TypeScript makeImmutable函数的具体用法?TypeScript makeImmutable怎么用?TypeScript makeImmutable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: makeImmutable

import { makeImmutable } from "immuts";
import { LOCATION_CHANGE } from "react-router-redux";
import { IAction } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import { ILookupSetPayload, LOOKUP_SET, OPEN_CLOSE, SET_TITLE } from "./general.actions";

const initialState = makeImmutable({
    isNavOpen: false,
    title: "",

    lookup: {} as { [key: string]: any[] }
});

export type IGeneralState = typeof initialState;

const locationChange = (state: IGeneralState) => {
    // Close navigation once we navigate
    return state.__set(x => x.isNavOpen, false);
};

const openClose = (state: IGeneralState, action: IAction<boolean>) => {
    return state.__set(x => x.isNavOpen, action.payload);
};

const setLookupData = <T>(state: IGeneralState, action: IAction<ILookupSetPayload<T>>) => {
    return state.__set(x => x.lookup[action.payload.key], action.payload.data);
};

const setTitle = (state: IGeneralState, action: IAction<string>) => {
    return state.__set(x => x.title, action.payload);
};
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:31,代码来源:general.reducer.ts

示例2: makeImmutable

import { makeImmutable } from "immuts";
import { IAction, pending, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import { MapTemplateCacheEntry } from "../play/mapTemplateCache";
import * as Actions from "./mapPreview.actions";

const initialState = makeImmutable({
    isLoading: true,
    mapTemplate: null as MapTemplateCacheEntry
});

export type IMapPreviewState = typeof initialState;

const done = (state: IMapPreviewState, action: IAction<MapTemplateCacheEntry>) => {
    return state.__set(x => x, {
        isLoading: false,
        mapTemplate: action.payload
    });
};

const loading = (state: IMapPreviewState, action: IAction<void>) => {
    return state.__set(x => x.isLoading, true);
};

export const mapPreview = <TPayload>(
    state = initialState,
    action?: IAction<TPayload>) => {

    return reducerMap(action, state, {
        [pending(Actions.loadMapPreview.TYPE)]: loading,
        [success(Actions.loadMapPreview.TYPE)]: done
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:31,代码来源:mapPreview.reducer.ts

示例3: makeImmutable

export const initialState = makeImmutable({
    gameId: 0,
    game: null as Game,

    gameChat: {
        // Initially do not allow sending messages, until state is retrieved
        isPending: true,
        all: [] as GameChatMessage[],
        team: [] as GameChatMessage[]
    },

    historyTurn: null as HistoryTurn,

    /** Current user's player */
    player: null as Player,
    mapTemplate: null as MapTemplateCacheEntry,

    placeCountries: {} as { [id: string]: number },

    twoCountry: {
        originCountryIdentifier: null as string,
        destinationCountryIdentifier: null as string,
        numberOfUnits: 0,
        minUnits: 0,
        maxUnits: 0,
        allowedDestinations: []
    } as ITwoCountry,

    attacksLeftPerTurn: 0,
    movesLeftPerTurn: 0,

    sidebarOpen: false,
    gameUiOptions: options && JSON.parse(options) || {
        showTeamsOnMap: true
    } as IGameUIOptions,
    overrideGameUiOptions: {
    } as Partial<IGameUIOptions>,

    operationInProgress: true,

    /** Value indicating whether current turn is displayed or history */
    historyActive: false,

    /** Other games where it's the player's turn */
    otherGames: [] as GameSummary[],

    error: null as ErrorResponse
});
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:48,代码来源:play.reducer.state.ts

示例4: makeImmutable

import { makeImmutable } from "immuts";
import { GameSummary } from "../../external/imperaClients";
import { IAction, pending, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import * as Actions from "./games.actions";

const initialState = makeImmutable({
    isLoading: false,
    games: {} as { [gameId: number]: GameSummary },
    openGames: [] as GameSummary[]
});

export type IMyGamesState = typeof initialState;

const refresh = (state: IMyGamesState, action: IAction<GameSummary[]>) => {
    // Convert to map
    let gameMap = {};

    if (action.payload) {
        for (let game of action.payload) {
            gameMap[game.id] = game;
        }
    }

    return state.__set(x => x, {
        isLoading: false,
        games: gameMap
    });
};

const refreshOpen = (state: IMyGamesState, action: IAction<GameSummary[]>) => {
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:31,代码来源:games.reducer.ts

示例5: makeImmutable

import { makeImmutable } from "immuts";
import { Alliance, AllianceJoinRequest, AllianceSummary } from "../../external/imperaClients";
import { IAction, pending, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import * as Actions from "./alliances.actions";

const initialState = makeImmutable({
    isLoading: false,
    alliances: [] as AllianceSummary[],
    /** Current alliance */
    alliance: null as Alliance,
    /** Requests for currenct alliance */
    requests: null as AllianceJoinRequest[],
    /** Requests for user */
    pendingRequests: null as AllianceJoinRequest[]
});

export type IAlliancesState = typeof initialState;

const refresh = (state: IAlliancesState, action: IAction<AllianceSummary[]>) => {
    return state.__set(x => x, {
        isLoading: false,
        alliances: action.payload
    });
};

const loading = (state: IAlliancesState, action: IAction<void>) => {
    return state.__set(x => x.isLoading, true);
};

const get = (state: IAlliancesState, action: IAction<typeof Actions.get.PAYLOAD>) => {
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:31,代码来源:alliances.reducer.ts

示例6: makeImmutable

import { makeImmutable } from "immuts";
import { NotificationSummary, UserInfo } from "../../external/imperaClients";
import { IAction, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import * as Actions from "./session.actions";

const initialState = makeImmutable({
    access_token: null as string,
    refresh_token: null as string,
    userInfo: null as UserInfo,
    isLoggedIn: false,
    language: "en" as string,
    notifications: null as NotificationSummary
});
export type ISessionState = typeof initialState;

const login = (state: ISessionState, action: IAction<Actions.ILoginPayload>) => {
    return state.__set(x => x, {
        access_token: action.payload.access_token,
        refresh_token: action.payload.refresh_token,
        isLoggedIn: true,
        userInfo: action.payload.userInfo,
        notifications: action.payload.notifications
    });
};

/** Store updated tokens */
const refresh = (state: ISessionState, action: IAction<Actions.IRefreshPayload>) => {
    return state.__set(x => x, {
        access_token: action.payload.access_token,
        refresh_token: action.payload.refresh_token
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:31,代码来源:session.reducer.ts

示例7: makeImmutable

import { GameSummary, Tournament, TournamentSummary, TournamentTeam } from "../../external/imperaClients";
import { IAction, pending, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import * as Actions from "./tournaments.actions";
import { makeImmutable, push, remove } from "immuts";

const initialState = makeImmutable({
    isLoading: false,
    tournaments: [] as TournamentSummary[],
    tournament: null as Tournament,
    pairingGames: [] as GameSummary[]
});

export type ITournamentsState = typeof initialState;

const refresh = (state: ITournamentsState, action: IAction<TournamentSummary[]>) => {
    return state.__set(x => x, {
        isLoading: false,
        tournaments: action.payload
    });
};

const load = (state: ITournamentsState, action: IAction<Tournament>) => {
    return state.__set(x => x, {
        isLoading: false,
        tournament: action.payload
    });
};

const loadPairingGames = (state: ITournamentsState, action: IAction<GameSummary[]>) => {
    return state.__set(x => x.pairingGames, action.payload);
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:31,代码来源:tournaments.reducer.ts

示例8: makeImmutable

import { makeImmutable } from "immuts";
import { FolderInformation, Message, MessageFolder } from "../../external/imperaClients";
import { IAction, pending, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import * as Actions from "./messages.actions";

const initialState = makeImmutable({
    isLoading: false,
    folderInformation: null as FolderInformation[],
    currentFolder: null as MessageFolder,
    currentMessages: [] as Message[],

    currentMessage: null as Message
});

export type IMessagesState = typeof initialState;

const switchFolder = (state: IMessagesState, action: IAction<Actions.ISwitchFolderPayload>) => {
    const { folder, messages } = action.payload;

    if (messages) {
        messages.sort((a, b) => b.sentAt.getTime() - a.sentAt.getTime());
    }

    return state.__set(x => x, {
        currentFolder: folder,
        currentMessages: messages || []
    });
};

const loadPending = (state: IMessagesState, action: IAction<FolderInformation[]>) => {
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:31,代码来源:messages.reducer.ts

示例9: makeImmutable

import { makeImmutable } from "immuts";
import { NewsItem } from "../../external/imperaClients";
import { IAction, pending, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import * as Actions from "./news.actions";

const initialState = makeImmutable({
    isLoading: false,
    news: [] as NewsItem[]
});

export type INewsState = typeof initialState;

const refresh = (state: INewsState, action: IAction<NewsItem[]>) => {
    return state.__set(x => x.news, action.payload).__set(x => x.isLoading, false);
};

const loading = (state: INewsState, action: IAction<NewsItem[]>) => {
    return state.__set(x => x.isLoading, true);
};

export const news = <TPayload>(
    state = initialState,
    action?: IAction<TPayload>) => {

    return reducerMap(action, state, {
        [pending(Actions.refresh.TYPE)]: loading,
        [success(Actions.refresh.TYPE)]: refresh
    });
};
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:30,代码来源:news.reducer.ts

示例10: makeImmutable

import { makeImmutable } from "immuts";
import { Ladder, LadderSummary } from "../../external/imperaClients";
import { IAction, pending, success } from "../../lib/action";
import reducerMap from "../../lib/reducerMap";
import * as Actions from "./ladders.actions";

const initialState = makeImmutable({
    isLoading: false,
    ladders: {} as { [ladderId: number]: LadderSummary },
    /** Current ladder */
    ladder: null as Ladder
});

export type ILaddersState = typeof initialState;

const refresh = (state: ILaddersState, action: IAction<LadderSummary[]>) => {
    // Convert to map
    let ladderMap = {};

    if (action.payload) {
        for (let ladder of action.payload) {
            ladderMap[ladder.id] = ladder;
        }
    }

    return state.__set(x => x, {
        isLoading: false,
        ladders: ladderMap
    });
};
开发者ID:cschleiden,项目名称:imperaplus-client,代码行数:30,代码来源:ladders.reducer.ts


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