Topics:
- JavaScript Style
- Total.js
- Using
require() - CSS / Styles
- UI components / jComponent
- Total.js
- SQL scripts in Total.js
- Folders/Files structure
- filenames should be all lowercase
- use
-dashes instead of_underscores for filenames
- use
tabs(tab width4) instead ofspaces - remove all unnecessary white-spaces
- always use
;semicolon at the end of the command - don't use
constconstant in the method scopes - short strings should be always wrapped in
'apostrophes - avoid adding dependencies as much as possible
- learn from our existing code
- use classic
loopsoverforEach()where possible
Basics:
// BAD:
var num=123;
// GOOD:
var num = 123;
// BAD:
var str = "Total.js";
// GOOD:
var str = 'Total.js';Semicolons:
// BAD:
someobj.somefn = function() {
}
// or
var a
var b
var c
// GOOD:
someobj.somefn = function() {
};
var a;
var b;
var c;Declaration:
// BAD:
someobj.somefn = function() {
const age = 30;
};
// GOOD:
someobj.somefn = function() {
var age = 30;
// or
// let age = 30;
};Conditions:
// BAD:
if(true) {doSomething();}
// or
if(true) doSomething();
// or
if (true) {
doSomething();
}
// GOOD:
if (true)
doSomething();
// or for a simple conditions you can use inline expression:
true && doSomething();We recommend using similar variable/schema names across all projects. In most cases, our projects use these variable names:
idnamevalueemailitemsorarrcontains an object collection/arrayitemtmpdtcreateddtupdated
Schemas:
- schema names must be in plural
- first char in uppercase
- always use
UID()for generating identifiers
// BAD:
NEWSCHEMA('user', function(schema) {
schema.define('name', 'Capitalize2(40)', true);
});
// GOOD:
NEWSCHEMA('Users', function(schema) {
schema.define('name', 'Capitalize2(40)', true);
});- use
constinstead ofvar - always use first upper-case letter in the variable name
Example:
// BAD:
var path = require('path');
// GOOD:
const Path = require('path');- filenames should be all lowercase
- for filenames use
-dashes instead of_underscores for filenames - keep styles in the same line
- don't use vendor prefixes, but use
/*auto*/comment for Total.js auto-prefixing - instead of quotes use
'apostrophes - don't use LESS or SASS because Total.js supports variables and nested selector too
/*auto*/
.class { key1: value; key2: value; key3: value; }
.class > div { key1: value; key2: value; }- keep all names in Plugins/Components/FUNC./MAIN./REPO. in lowercase
- keep all variables in lowercase
- do not create complicated objects with a lot of objects in depth (keep max. 2-3 of keys in depth)
- if you can, do not use
_underscore for variables - keep same variable/plugin names across all projects
- think reusable
// =======================================
// PLUGINS
// =======================================
// BAD:
PLUGIN('Name', function(plugin) {
plugin.doSomething = function() {
};
});
// GOOD:
PLUGIN('name', function(exports) {
// keep "exports." name and keep all names in lowercase
exports.dosomething = function() {
};
});
// =======================================
// COMPONENTS
// =======================================
// BAD:
COMPONENT('Name', function(com, settings) {
});
// GOOD:
COMPONENT('name', function(self, config, cls) {
// keep names: "self.", "config" and "cls"
});- table names / field names should be all lowercase
- use
tabs(tab width4) instead ofspaces - remove all unnecessary white-spaces
- always use
;semicolon at the end of a SQL command - remove all unnecessary type-casting
name<>'something'::texttoname<>'something' - format SQL scripts
- divide scripts TABLES, VIEWS, STORED PROCEDURES/FUNCTIONS, INDEXES
- table names starts with
tbl_in singular -->tbl_user,tbl_product - tables with codelists must start with
cl_in singular -->cl_type,cl_product - view names starts with
view_in singular -->view_user - stored procedures starts with
sp_in singular -->sp_user, etc.. - functions starts with
fn_in singular -->fn_user, etc..
Fields creating:
- dates starts with
dt-->dtcreated,dtupdated,dtpaid, etc.. - booleans must starts with
is-->ispaid,isremoved,ispublished, etc.. with few exceptions - identifiers
id(primary key),userid(foreign key),productid(foreign key), etc.. - use
textdata types instead ofvarchar(more info) - keep same names in different tables for example:
name,body, etc.. - keep short names
- if the situation allows it, use always these columns
id,nameanddtcreated - keep the sort of fields below:
-- BAD:
CREATE TABLE "public"."tbl_channel_message" (
"channelid" varchar(25),
"body" text,
"id" varchar(25) NOT NULL,
"ispinned" bool DEFAULT FALSE,
"isrobot" bool DEFAULT FALSE,
"userid" varchar(25),
"countupdate" INT2 DEFAULT 0,
"dtupdated" timestamp,
"openplatformid" varchar(30),
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
"ismobile" bool DEFAULT FALSE,
"isremoved" bool DEFAULT FALSE,
PRIMARY KEY ("id")
);
-- GOOD:
CREATE TABLE "public"."tbl_channel_message" (
-- IDENTIFIERS FIRST
"id" text NOT NULL,
"userid" text,
"channelid" text,
"openplatformid" text,
-- MAIN FIELDS
"body" text,
-- NUMBERS
"countupdate" INT2 DEFAULT 0,
-- BOOLEANS
"ismobile" bool DEFAULT FALSE,
"ispinned" bool DEFAULT FALSE,
"isremoved" bool DEFAULT FALSE,
"isrobot" bool DEFAULT FALSE,
-- AND LAST DATES
"dtupdated" timestamp,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
-- DO NOT FORGET FOR FOREIGN KEYS
CONSTRAINT ...
CONSTRAINT ...
PRIMARY KEY ("id")
);Keep the file structure according to the file types:
/img/for images/js/for scripts/css/for styles/fonts/for fonts/videos/for videos
Use - dashes for spaces instead of underscores _ for the filenames.