TypeScript @ajp-utils-ts-utils.str_enum类(方法)实例源码

下面列出了TypeScript @ajp-utils-ts-utils.str_enum 类(方法)源码代码实例,从而了解它的用法。

作者:AJamesPhillip    项目:napth   
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);
}

作者:AJamesPhillip    项目:napth   
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,

作者:AJamesPhillip    项目:napth   
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;
}

作者:AJamesPhillip    项目:napth   
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;

作者:AJamesPhillip    项目:napth   
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;


问题


面经


文章

微信
公众号

扫码关注公众号