本文整理匯總了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>,