Skip to content

totaljs-es/guidelines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Topics:

JavaScript Style

Filenames

  • filenames should be all lowercase
  • use - dashes instead of _ underscores for filenames

Common

  • use tabs (tab width 4) instead of spaces
  • remove all unnecessary white-spaces
  • always use ; semicolon at the end of the command
  • don't use const constant 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 loops over forEach() where possible

Examples

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();

Total.js

We recommend using similar variable/schema names across all projects. In most cases, our projects use these variable names:

  • id
  • name
  • value
  • email
  • items or arr contains an object collection/array
  • item
  • tmp
  • dtcreated
  • dtupdated

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);

});

Using require()

  • use const instead of var
  • always use first upper-case letter in the variable name

Example:

// BAD:
var path = require('path');

// GOOD:
const Path = require('path');

CSS / Styles

  • 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; }

UI components / jComponent

  • 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"
});

SQL scripts in Total.js

  • table names / field names should be all lowercase
  • use tabs (tab width 4) instead of spaces
  • remove all unnecessary white-spaces
  • always use ; semicolon at the end of a SQL command
  • remove all unnecessary type-casting name<>'something'::text to name<>'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 text data types instead of varchar (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, name and dtcreated
  • 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")
);

Folders/Files structure

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.

About

Total.js guidelines

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors