New Total.js framework version 2.7.0
This version brings a few fixes and improvements.
News
Static files of Components
I have improved rendering of group of components @{components('group'}
. Now the framework links static files from rendered groups only. In other words: each group of components has its own scripts and styles. This change is a good news for applications using a lot of components.
Prototypes
With this version you can extend some Total.js prototypes easily. Just extend prototype:
F.prototypes(function(proto) {
// proto.Chunker
// proto.Controller
// proto.Database
// proto.DatabaseBinary
// proto.DatabaseBuilder
// proto.DatabaseBuilder2
// proto.DatabaseCounter
// proto.ErrorBuilder
// proto.HttpFile
// proto.HttpRequest
// proto.HttpResponse
// proto.Image
// proto.Message
// proto.Page
// proto.Pagination
// proto.RESTBuilder
// proto.RESTBuilderResponse
// proto.SchemaBuilder
// proto.SchemaOptions
// proto.TransformBuilder
// proto.UrlBuilder
// proto.WebSocket
// proto.WebSocketClient
});
Changed default IP
I have changed default IP from 127.0.0.1
to 0.0.0.0
. This change has multiple benefits:
- app can run on
localhost
or 127.0.0.1
- app can run on your machine IP e.g.
192.168.200.1
- Amazon EC2 and another similar services use
0.0.0.0
IP for Node.js apps
Controller can be changed in the schema directly
In some cases it's very important to change a controller dynamically and directly in the schema. I have extend SchemaBuilderEntity
by adding a new method .$controller(new_controller)
.
For example:
model.$controller(NEW_INSTANCE_OF_CONTROLLER);
model.$save();
Only a few developers know that NoSQL supports meta-data - key-value
storage. I have extended database object by adding new methods:
var db = NOSQL('orders');
db.set('numbering', (db.get('numbering') || 0) + 1);
Meta-data are stored in plain-text JSON file: orders.nosql-meta
and all meta-data are read into the memory automatically when the DB is loaded.
Improved Unit-Testing
I have improved unit-testing in Total.js framework. Read more information about new unit-testing system in Total.js documentation or follow this example.
Example of some test:
TEST('controller.increment()', function() {
FAIL(F.controller('default').functions.increment(1) !== 2);
});
TEST('Test URL 1', '/1/', function(builder) {
// builder === RESTBuilder
builder.get();
builder.exec(function(err, response, output) {
FAIL(output.response !== '1');
});
});
TEST('Test URL 2', '/2/', function(builder) {
// builder === RESTBuilder
builder.get();
builder.exec(function(err, response, output) {
FAIL(output.response !== '2', 'additional description');
OK(output.status === 200, 'HTTP status');
});
});
TEST('Test URL 3', '/3/', function(builder) {
// builder === RESTBuilder
builder.json({ data: 4 });
builder.exec(function(err, response) {
FAIL(response.data !== 3);
});
});
RESULT:
====================================================
PID : 51109
Node.js : v8.1.3
Total.js : v2.7.0
OS : darwin 16.6.0
====================================================
Name : Total.js
Version : 1.0.0
Author : Peter Širka
Date : 2017-07-03 11:06:28
Mode : debug
====================================================
http://0.0.0.0:8000/
===================== TESTING ======================
[ TEST: default.js ]
Passed ............. controller.increment() [1 ms]
Passed ............. Test URL 1 [22 ms]
Passed ............. Test URL 2 <additional description> [6 ms]
Passed ............. Test URL 2 <HTTP status> [6 ms]
Failed [x] ......... Test URL 3 [6 ms]
===================== RESULTS ======================
> Passed ......... 4/4
> Failed [x] ..... 1/4
Improved RESTBuilder
I have added a new features into the RESTBuilder:
instance.robot()
extends user-agent by adding bot
keyword
instance.mobile()
extends user-agent by adding iPhone
keyword
instance.file(name, filename, [buffer])
can upload file as multipart/form-data
Follow Total.js Framework on Twitter and give a star on Github.