From c62573dc5c786eafed4bf7fd743b51ec0270c351 Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Tue, 11 Aug 2015 13:26:05 +0200 Subject: [PATCH] Updated docs for classes. --- CHANGELOG | 2 + .../Books/Users/Foxx/Develop/Model.mdpp | 33 +++++++------- .../Books/Users/Foxx/Develop/Repository.mdpp | 44 ++++++++++--------- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0c27e4f686..d8477fd99f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -137,6 +137,8 @@ v2.7.0 (XXXX-XX-XX) * added optional Foxx dependencies +* converted Foxx constructors to classes + * updated chai to 3.0. diff --git a/Documentation/Books/Users/Foxx/Develop/Model.mdpp b/Documentation/Books/Users/Foxx/Develop/Model.mdpp index 4b90acfde7..8ceb027ac7 100644 --- a/Documentation/Books/Users/Foxx/Develop/Model.mdpp +++ b/Documentation/Books/Users/Foxx/Develop/Model.mdpp @@ -8,8 +8,9 @@ your model file, export the model as **model**. ```js var Foxx = require("org/arangodb/foxx"); -var TodoModel = Foxx.Model.extend({ -}); +class TodoModel extends Foxx.Model { + // ... +} exports.model = TodoModel; ``` @@ -26,13 +27,14 @@ For more information on the syntax see [the official joi documentation](https:// var Foxx = require("org/arangodb/foxx"); var joi = require("joi"); -var PersonModel = Foxx.Model.extend({ - schema: { - name: joi.string().required(), - age: joi.number().integer(), - active: joi.boolean().default(true) - } -}); +class PersonModel extends Foxx.Model { + // ... +} +PersonModel.prototype.schema = { + name: joi.string().required(), + age: joi.number().integer(), + active: joi.boolean().default(true) +}; exports.model = PersonModel; ``` @@ -40,12 +42,13 @@ exports.model = PersonModel; You can also use `joi.object` schemas directly: ```js -var PersonModel = Foxx.Model.extend({ - schema: joi.object().keys({ - name: joi.string().required(), - age: joi.number().integer(), - active: joi.boolean().default(true) - }) +class PersonModel extends Foxx.Model { + // ... +} +PersonModel.prototype.schema = joi.object().keys({ + name: joi.string().required(), + age: joi.number().integer(), + active: joi.boolean().default(true) }); ``` diff --git a/Documentation/Books/Users/Foxx/Develop/Repository.mdpp b/Documentation/Books/Users/Foxx/Develop/Repository.mdpp index c0a58691b7..11ea9b95f6 100644 --- a/Documentation/Books/Users/Foxx/Develop/Repository.mdpp +++ b/Documentation/Books/Users/Foxx/Develop/Repository.mdpp @@ -5,8 +5,9 @@ A repository is a gateway to the database. It gets data from the database, updat ```javascript var Foxx = require("org/arangodb/foxx"); -var TodosRepository = Foxx.Repository.extend({ -}); +class TodosRepository extends Foxx.Repository { + // ... +} exports.repository = TodosRepository; ``` @@ -27,8 +28,7 @@ Model lifecycle: ```js var person = new PersonModel(); person.on('beforeCreate', function() { - var model = this; - model.fancyMethod(); // Do something fancy with the model + this.fancyMethod(); // Do something fancy with the model }); var people = new Repository(appContext.collection("people"), { model: PersonModel }); @@ -70,11 +70,12 @@ Making a simple query in the repository and using it from the controller: // in the repository var Foxx = require("org/arangodb/foxx"); -var TodosRepository = Foxx.Repository.extend({ - getPendingItems: Foxx.createQuery( - 'FOR todo IN my_todos FILTER todo.completed == false RETURN todo' - ) +class TodosRepository extends Foxx.Repository { + // ... }); +TodosRepository.prototype.getPendingItems = Foxx.createQuery( + 'FOR todo IN my_todos FILTER todo.completed == false RETURN todo' +); // in the controller ctrl.get("/", function(req, res) { @@ -86,10 +87,10 @@ It is also possible to supply parameters to the query: ```js // in the repository -getPendingItemById: Foxx.createQuery({ +TodosRepository.prototype.getPendingItemById = Foxx.createQuery({ query: 'FOR todo IN my_todos FILTER todo.completed == false FILTER todo._key == @id RETURN todo', params: ['id'] -}) +}); // in the controller ctrl.get("/:id", function(req, res) { @@ -103,7 +104,7 @@ The list of results can also be transformed before returning it from the reposit ```js // in the repository -getPendingItemById: Foxx.createQuery({ +TodosRepository.prototype.getPendingItemById = Foxx.createQuery({ query: 'FOR todo IN my_todos FILTER todo.completed == false FILTER todo._key == @id RETURN todo', params: ['id'], transform: function(results, extra) { @@ -111,7 +112,7 @@ getPendingItemById: Foxx.createQuery({ results[i].extraProperty = extra; } } -}) +}); // in the controller ctrl.get("/:id", function(req, res) { @@ -152,15 +153,16 @@ The syntax for defining indexes is the same used in [*collection.ensureIndex*](. ```js var Foxx = require('org/arangodb/foxx'); -var FulltextRepository = Foxx.Repository.extend({ - indexes: [ - { - type: 'fulltext', - fields: ['text'], - minLength: 3 - } - ] -}); +class FulltextRepository extends Foxx.Repository { + // ... +} +FulltextRepository.prototype.indexes = [ + { + type: 'fulltext', + fields: ['text'], + minLength: 3 + } +]; ``` !SECTION Methods of a Repository