当前位置: 首页>>代码示例>>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;未经允许,请勿转载。