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


TypeScript utils.str_enum函數代碼示例

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


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

示例1: str_enum

import {str_enum} from "@ajp/utils-ts/utils";

import {BaseModel} from "../../../shared/models/base";

export const FETCH_STATES = str_enum(["IDLE", "FETCHING", "FETCH_SUCCESS", "FETCH_FAILED"]);
export type FETCH_STATE = keyof typeof FETCH_STATES;

let TEMP_ID = Math.round(Math.random() * -2047483647);

export function temp_id () {
    return `${--TEMP_ID}`;
}

export const OFFSET_SECONDS = 10;

/**
 * Make a date in the future to simulate what might be created on the server.
 * This should help avoid elements in a list thrashing about when they're created
 * though will have the effect of things being created in the future.
 */
export function new_date() {
    return new Date(new Date().getTime() + (OFFSET_SECONDS * 1000));
}

/**
 * If model is not save yet, return date to non offset date
 */
export function correct_date(date: Date): Date {
    const offset = OFFSET_SECONDS * 1000;
    return new Date(date.getTime() - offset);
}
開發者ID:AJamesPhillips,項目名稱:napthr,代碼行數:31,代碼來源:util.ts

示例2: require

import * as _ from "lodash";
import {Reducer} from "redux";
import reduceReducers = require("reduce-reducers");
import {str_enum} from "@ajp/utils-ts/utils";

import {ACTIONS, Actions} from "../actions";
import {get_bootstrapped_data} from "../bootstrap";

export const STATUSES = str_enum(["SIGNED_OUT", "SIGNING_IN", "SIGNED_IN", "SIGNING_OUT"]);
export type STATUS = keyof typeof STATUSES;

export interface State {
    status: STATUS;
    last_signout_erred: boolean;
    last_failed_signin: {
        status_text: string | undefined;
        status_code: number | undefined;
    } | {
        status_text?: undefined;
        status_code?: undefined;
    };
}

function init_state (state: State) {

    if (!state || _.keys(state).length === 0) {

        const bootstrap = get_bootstrapped_data();
        const status = bootstrap && bootstrap.session.status === "SIGNED_IN" ? STATUSES.SIGNED_IN : STATUSES.SIGNED_OUT;
        state = {
            status,
開發者ID:AJamesPhillips,項目名稱:napthr,代碼行數:31,代碼來源:reducer.ts

示例3: str_enum

    return user;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                   Views                                   *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

export const USER_VIEW_KINDS = str_enum([
    "User_AdminView",
    "User_OwnerView",
    "User_PublicView",
]);
export type USER_VIEW_KIND = keyof typeof USER_VIEW_KINDS;

// tslint:disable-next-line
export interface User_AdminView extends BaseModel {
    kind: "User_AdminView";
    email: string;
    is_admin: boolean;
    admin_notes: string;
    added_by_admin_uuid: string | null;

    // Prevent password being set
    password?: undefined;
}
開發者ID:AJamesPhillips,項目名稱:napthr,代碼行數:31,代碼來源:user.ts

示例4: str_enum

    created_at: Date;
    modified_at: Date | null;
    deleted_at: Date | null;
}

/**
 * Extra fields that may be exchanged between server and client
 */
export interface BaseModel extends BaseDbFields {
    // Temporary fields
    old_temp_id?: string;
    sync_state?: SYNC_STATE;
    sync_error?: string;
}

export const SYNC_STATES = str_enum(["NOT_SYNCED", "SYNCING", "SYNCED", "ERROR"]);
export type SYNC_STATE = keyof typeof SYNC_STATES;

/**
 * Turns the fields in a model in POJO form to instances of the desired types
 * Used by to convert from db entries and from frontend Redux store?
 */
export function from_pojo<U extends BaseModel>(instance: U): U {
    // instance.saved = parse_bool(instance.saved);
    // instance.saving = parse_bool(instance.saving);

    instance.created_at = parse_date(instance.created_at);
    instance.modified_at = parse_date(instance.modified_at);
    instance.deleted_at = parse_date(instance.deleted_at);

    return instance;
開發者ID:AJamesPhillips,項目名稱:napthr,代碼行數:31,代碼來源:base.ts

示例5: str_enum

import {str_enum} from "@ajp/utils-ts/utils";

export const ERRORS = str_enum([
    // General errors
    "UNKNOWN_ERROR",

    // Request errors
    "KEY_MISSING",

    // Model errors
    "FIELD_MISSING",
    "FIELD_INVALID",
    "EMAIL_FIELD_INVALID",
    "NAME_FIELD_INVALID",

    // User creation
    "EMAIL_ALREADY_REGISTERED",

    // Session creation
    "ALREADY_SIGNED_IN",
    "ALREADY_SIGNED_OUT",
    "EMAIL_OR_PASSWORD_NOT_RECOGNISED",
]);
export type ERROR = keyof typeof ERRORS;
開發者ID:AJamesPhillips,項目名稱:napthr,代碼行數:24,代碼來源:errors.ts


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