• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript utils.str_enum函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript json-rpc-ws.Client类代码示例发布时间:2022-05-28
下一篇:
TypeScript core.MapsAPILoader类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap