Total.js v2.9.0

Thu Nov 16 2017 07:43:54 GMT+0100 (Central European Standard Time), Peter Širka

Total.js v2.9.0

This version brings one great new feature, some bug fixes and great improvements. Make sure to update to the latest version. It's more stable than previous version. Both old and new version of the framework work with Node v9 without any problems.


New WebSocketClient

This is the biggest new feature. Now you can connect via WebSocket from Total.js as a client. Implementation is very simple. WEBSOCKETCLIENT(callback) is a global method:

require('total.js');

WEBSOCKETCLIENT(function(client) {

    client.connect('ws://127.0.0.1:8000/');

    client.on('open', function() {
        console.log('OPEN');
    });

    client.on('close', function() {
        console.log('CLOSE');
    });

    client.on('message', function(message) {
        console.log('MESSAGE', message);
    });

    // Default options:
    // client.options.type = 'json';
    // client.options.compress = true;
    // client.options.reconnect = 3000;
    // client.options.encodedecode = true;

    // Sending:
    // client.send({ some: 'object' });

});

New WebSocketClient supports:

  • compression
  • auto-reconnection when the connection is lost
  • encode-decode UTF-8 messages according to the Total.js server-side WebSocket implementation

Can I connect Total.js app with another Total.js app via WebSocket?
From now on, yes.

Improved WebSocket

My big friend Jozef Gula did a great job improving Total.js WebSockets. As he said, there were a few issues with the previous implementation. The new changes improve stability and performance.

Fixed WebSocket + ArrayBuffer

I found a problem in ArrayBuffer type in binary mode in WebSocket + I have extend ArrayBuffer prototype by adding ArrayBuffer.toBuffer() method. Now you can easily convert ArrayBuffer to Buffer.

Good to know:
The framework converts Buffer to ArrayBuffer automatically if you are sending a raw Buffer via client.send() or controller.send().

Improved performace

I have improved a routing performance and executing of controllers.

Improved schemas

I have improved Schemas implementation. The new implementation can save a lot of code and here is the example of new usage:

NEWSCHEMA('User').make(function(schema) {

    // This will work in +2.5.0
    schema.addWorkflow('someworkflow', function($) {

        // $.model
        // $.callback
        // $.error
        // $.options
        // $.controller

    });

    // This will work in +2.9.0
    schema.addWorkflow('someworkflow', function($) {

        // is the alias for $.callback(SUCCESS(true));
        // this method executes a callback with SUCCESS()
        $.success();

    });

    // This will work in +2.9.0
    schema.addWorkflow('someworkflow', function($) {

        // is the alias for $.error.push('error-permission') + $.callback();
        // this method executes a callback with error
        $.invalid('error-permissions');

    });

    // This will work in +2.9.0
    schema.addWorkflow('someworkflow', function($) {

        // it's the alias for $.controller.user
        // default: undefined (if the controller doesn't exist)
        $.user;

        // it's the alias for $.controller.session
        // default: undefined (if the controller doesn't exist)
        $.session;

        // it's the alias for $.controller.ip
        // default: undefined (if the controller doesn't exist)
        $.ip;

        // it's the alias for $.controller.query
        // default: undefined (if the controller doesn't exist)
        $.query;

        // it's the alias for $.controller.language
        // default: '' (if the controller doesn't exist)
        $.language;

    });

});

Inline schema validation

I have added an inline validation of defined fields in the schema. So you don't need to define schema.setValidate() delegate. It is very simple:

NEWSCHEMA('Person').make(function(schema) {

    schema.define('name', 'String');
    schema.define('age', 'Number', val => val > 50 ? true : 'You are too young');
    // or
    // schema.define('age', 'Number', val => val > 50);

});

Inline real-time enabling/disabling of schema validation

This feature is very important for more complicated schemas. This version of Total.js brings really great improvements for custom field validation.

NEWSCHEMA('Person').make(function(schema) {

    schema.define('name', 'String', true);
    schema.define('age', 'Number', true);

    // the validation for "age" will only be enabled if "name" contains a value "Peter"
    // otherwise the age field won't be validated
    schema.required('age', model => model.name === 'Peter');

    // You can specify more fields, for example:
    schema.required('company, companyid, companyvat', model => model.iscompany);

});

NoSQL backups

New version of Total.js supports reading of all backups from a database.

// Reads all backups
NOSQL('posts').backups(callback(err, response) {
    // @response {Array}
    var backup = response[0];

    // backup.id; {Number} Backup ID
    // backup.date; {Date} Date of backup
    // backup.user; {String} A user name who backed DB
    // backup.data; {Object} A backed document    
});

// Reads specific backups
NOSQL('posts').backups(backup => backup.data.type === 'products', callback(err, response) {
    // your code
});


Tags

Follow us

Latest blogs
Total.js Code Editor v1
Fri Dec 07 2018 22:55:13 GMT+0100 (Central European Standard Time)
New release: Total.js v3.1
Fri Dec 07 2018 11:41:40 GMT+0100 (Central European Standard Time)
New CDN for Flow + Dashboard + Flowboard
Sun Nov 04 2018 09:05:03 GMT+0100 (Central European Standard Time)
OpenPlatform v3
Mon Oct 15 2018 10:11:07 GMT+0200 (Central European Summer Time)
New Single Page Application template
Fri Oct 12 2018 21:25:34 GMT+0200 (Central European Summer Time)

Latest comments
Nice tip
Mauro Junior
Thu Sep 20 2018 21:41:02 GMT+0200 (Central European Summer Time)
Not only for Total.js. You can communicate with different websocket servers.
Peter Širka
Mon Apr 23 2018 20:08:20 GMT+0200 (Central European Summer Time)
Marko: you need to create a buffer with this codepage and write byte-to-byte string. I recommend ...
Peter Širka
Mon Apr 23 2018 20:06:21 GMT+0200 (Central European Summer Time)
Is WEBSOCKETCLIENT only for internal ws connections between totaljs apps?
Stelios Stephanua
Fri Mar 16 2018 06:04:22 GMT+0100 (Central European Standard Time)
Total.js is amazing! ;)
Leonardo Hessel
Tue Dec 19 2017 19:51:15 GMT+0100 (Central European Standard Time)

Pixabay


Read more

Total.js Code Editor v1

Products: Try our real-time collaboration tool for Total Developers. Code Editor offers great features for development.

Fri Dec 07 2018 22:55:13 GMT+0100 (Central European Standard Time)
New release: Total.js v3.1

News: I have released a new version of Total.js with bug fixes and with small improvements.

Fri Dec 07 2018 11:41:40 GMT+0100 (Central European Standard Time)
New CDN for Flow + Dashboard + Flowboard

News: I have changed CDN for Flow + Dashboard + Flowboard components to KeyCDN.

Sun Nov 04 2018 09:05:03 GMT+0100 (Central European Standard Time)
OpenPlatform v3

News: I have published a new version of OpenPlatform. New, better, faster, more secure and more simpler.

Mon Oct 15 2018 10:11:07 GMT+0200 (Central European Summer Time)
New Single Page Application template

News: I have published free, beautiful and simple Total.js + jComponent SPA template under MIT license.

Fri Oct 12 2018 21:25:34 GMT+0200 (Central European Summer Time)
Flow: How to find a specific component?

Tutorials: This tutorial shows you a quick way how to find a specific component in the Flow designer.

Mon Sep 03 2018 20:21:30 GMT+0200 (Central European Summer Time)1