本文整理汇总了TypeScript中normalizr.Schema.define方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Schema.define方法的具体用法?TypeScript Schema.define怎么用?TypeScript Schema.define使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类normalizr.Schema
的用法示例。
在下文中一共展示了Schema.define方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Schema
import {Schema, arrayOf} from 'normalizr';
import phone from './phone';
const contact = new Schema('contacts',{
idAttribute: '_id'
});
contact.define({phones: arrayOf(phone)});
export default contact;
示例2: Schema
import { normalize, Schema, arrayOf, valuesOf } from "normalizr";
export var article = new Schema("articles");
export var comment = new Schema("comments");
export var user = new Schema("users");
article.define({
get_comments : arrayOf(comment),
get_author : user,
});
comment.define({
get_author : user,
get_article : article,
});
user.define({
get_articles : arrayOf(article),
get_comments : arrayOf(comment),
});
示例3: Schema
/// <reference path="normalizr.d.ts" />
import { normalize, Schema, arrayOf, unionOf, valuesOf } from 'normalizr';
// First, define a schema for our entities:
const article1 = new Schema('articles');
const user1 = new Schema('users');
// Then we define nesting rules:
article1.define({
author: user1,
contributors: arrayOf(user1)
});
// Now we can use this schema in our API response handlers:
const ServerActionCreators = {
// These are two different XHR endpoints with different response schemas.
// We can use the schema objects defined earlier to express both of them:
receiveOneArticle(response: any) {
// Here, the response is an object containing data about one article.
// Passing the article schema as second parameter to normalize() lets it
// correctly traverse the response tree and gather all entities:
// BEFORE:
// {
// id: 1,
// title: 'Some Article',
示例4: Schema
*/
export const interactionSchema = new Schema('interaction', getOptions());
export const draftSchema = new Schema('draft', getOptions());
export const messageSchema = new Schema('message', getOptions());
export const replySchema = new Schema('reply', getOptions());
/**
* Schema setup for Customer
*/
export const customerSchema = new Schema('customer', getOptions());
export const userSchema = new Schema('user', getOptions());
export const caseChangesSchema = new Schema('changes', getOptions());
interactionSchema.define({
case: caseSchema
});
customerSchema.define({
cases: arrayOf(caseSchema)
});
caseSchema.define({
_embedded: {
customer: customerSchema,
draft: draftSchema,
message: messageSchema,
replies: arrayOf(interactionSchema),
foober: customerSchema
},
});
示例5: Record
import { List, Map, Record } from 'immutable'
import {userSchema, IUser} from '../user/user.schema'
export const PostRecord = Record({
id: null,
title: null,
body: null,
user: null,
deleting: false
})
export const postSchema = new Schema('posts')
postSchema.define({
user: userSchema
})
export interface IPost {
id: string
title: string
body: string
userId: number
user: any
}
export interface IPosts extends Map<String, any> {
result: List<Number>
entities: {
posts: Map<Number, IPost>,