Circular reference
/*
* User.js
*/
const User = attributes(
{
name: String,
friends: {
type: Array,
itemType: 'User', // << identifier
},
favoriteBook: {
type: 'BookStructure', // << identifier
required: true,
},
books: {
type: 'BooksCollection', // << identifier
itemType: String,
},
},
{
dynamics: {
/* dynamic types for each identifier */
User: () => User,
BookStructure: () => require('./Book'),
BooksCollection: () => require('./BooksCollection'),
},
}
)(class User {});
module.exports = User;
/*
* Book.js
*/
const Book = attributes(
{
name: String,
owner: 'User', // << dynamic type with inferred identifier
nextBook: 'BookStructure', // << dynamic type with custom identifier
},
{
identifier: 'BookStructure', // << custom identifier
dynamics: {
/* dynamic types for each identifier */
User: () => require('./User'),
BookStructure: () => Book,
},
}
)(class Book {});
module.exports = Book;Dynamic type identifier
Inferred identifier
Custom identifier
Concrete type definition inside dynamics
dynamicsWith CommonJS modules
With ES Modules
Last updated