Topics:
- 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 any 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();- 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; }- schema names must be in plural
- first char in uppercase
// BAD:
NEWSCHEMA('user', function(schema) {
schema.define('name', 'Capitalize2(40)', true);
});
// GOOD:
NEWSCHEMA('Users', function(schema) {
schema.define('name', 'Capitalize2(40)', true);
});- 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)
- 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
- divided 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 - identificators
id(primary key),userid(foreign key),productid(foreign key), etc.. - Total.js identificators: Total.js UID =
VARCHAR(25), OpenPlatformID =VARCHAR(30) - keep same names in different tables for example:
name,body, etc.. - keep short names
- 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 now(),
"ismobile" bool DEFAULT FALSE,
"isremoved" bool DEFAULT FALSE,
PRIMARY KEY ("id")
);
-- GOOD:
CREATE TABLE "public"."tbl_channel_message" (
-- IDENTIFICATORS FIRST
"id" varchar(25) NOT NULL,
"userid" varchar(25),
"channelid" varchar(25),
"openplatformid" varchar(30),
-- 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 NOW(),
-- DO NOT FORGET FOR FOREIGN KEYS
CONSTRAINT ...
CONSTRAINT ...
PRIMARY KEY ("id")
);- Use Total.js Code Editor for development
- (c) 2012-2020 by Peter Širka - petersirka@gmail.com
- Contact us via https://www.totaljs.com/contact/
- info@totaljs.com