Greetings to all.I do not know how correctly I described this library in the title, but I want to tell you about it.

What is it?
The library
TOM.js makes it possible to facilitate such tasks as:
- loading / uploading scripts / stylesheets with dependencies
- class creation / inheritance
- interception of functions within the application
Why is it if there are analogues?
I am well aware of the fact that there are all sorts of
RequireJS ,
klass.js, and so on, but this library is a development for several years for specific tasks in the project I'm working on.
')
For example, I never met the function call interception functionality, but we needed this functionality in the project for developing extensions for all occasions, and later for other tasks. And there already is the creation of classes with the necessary set of parameters and functions, and, of course, the file loader created taking into account the specifics of our project.
TOM.boot - loading modules and scripts with dependencies
Initially it was a small library, which in 4 years was rewritten several times already due to unpleasant dependency bugs. The last time was an attempt to implement a load using
RequireJS , with a small "add-in", but in the end this "add-in" turned out to be so twisted
(and also RequireJS had dependencies on its own concepts), which turned out to be easier to implement its bootloader, but without allowing any errors were in past implementations.
What can this part of the library?
Loading modules and scripts
To load "modules" (I will talk about them a little below) and scripts, you can use about 5 variations of calls
1 way , task: download /libraries/jquery/jquery.boot.js and /libraries/scroll/scroll.boot.js
TOM.boot.load( 'libraries/*', [ 'jquery', 'scroll' ], function( ){ } );
2 way , task: download /jquery/jquery.boot.js
TOM.boot.load( '*', 'jquery', function( ){ } );
3 way , task: download /jquery.boot.js
TOM.boot.load( '', 'jquery', function( ){ } );
4 way , task: load / jquery.js
TOM.boot.load( '', 'jquery.js', function( ){ } );
5 way , task: download code.jquery.com/jquery-1.12.0.min.js
TOM.boot.load( '', 'https://code.jquery.com/jquery-1.12.0.min.js', function( ){ } );
As you can see from the examples - the structure of the call function is as follows:
TOM.boot.load( ' /', ' /' { }, 'callback ' );
The logic of selecting the full path is simple here - if there is no extension in the name, then we load the module (* .boot.js) , if there is, then a specific file. A * (asterisk) in the path substitutes the name of the module / file in this place, which allows you to save a clear directory and file structure in large applications.
Loading scripts from the module with dependencies
To begin with, you should understand what a “module” is in the understanding of this library.
A module is a * .boot.js file that contains specific files and their dependencies on other “modules” and scripts.
The contents of * .boot.js look like this:
TOM.boot.initiate( 'button', [ { file: '*.style.css' },
Here the structure is as follows:
TOM.boot.initiate( ' ', ' ' );
Well, the objects themselves downloadable files have the following structure:
- file is the name of the file to be loaded, where * (asterisk) substitutes the module name
- require - dependency (list of dependencies) both on the files of the current module and on other modules
- initialize - function (list of functions) that should be executed after loading the script
- main - a boolean variable indicating that everything in this module depends on the file
TOM.processor - interception of functions performed within the application
In fact, the interception of functions will take place only where you need it, only in those objects that you “proxy”.
In our project, for example, there are 3 objects that are registered in the
window and with which we work, these are our so-called “scopes”:
api ,
core ,
interface and we work with them, therefore we only proxify them.
TOM.js by default creates the
core and
interface , but working with them or not is a private matter for everyone.
How to work with it?
Proxy
The first thing that needs to be done is to make “proxying” of the necessary objects in a similar way:
TOM.processor.proxy( core ); TOM.processor.proxy( interface );
The essence of proxying is simple to ugliness - we pass through the object and wrap the functions with a certain look (add pre-callback and post-callback) .
Handling / Intercepting Function Calls
After processing the necessary objects, the functions called inside them can be processed in a similar way:
The handler has the following structure:
TOM.processor.bind( '{pre post}- ', 'callback ', '' );
- pre or post is the “before calling” processing of the original function, or after — respectively
- parameters is an object with the settings of this handler
- stage - analogue of pre / post in function name
- label - “label” by which we can remove this particular processor without affecting others.
- priority - add this handler to the beginning or to the end of the queue?
Other features
In addition to the ability to directly add and remove "handlers", you can also:
- "Initiate fake events":
TOM.processor.signal( ' (pre/post)', ' ', ' ', '' );
- perform one-time event handling:
TOM.processor.one( ' TOM.processor.bind' );
TOM.classes - creating and inheriting classes
This part of the library beats the standard approach to creating and inheriting classes in standard
JavaScript , but with a large number of nuances and developments.
How to create / inherit a class?
- 1st method
TOM.classes.create( ' / ', ' ', ' ',
- 2nd way
TOM.classes.create( ' / ', ' ', ' ',
- 3rd way - the same as 2nd - but in the array is also a constructor
What are the features of this script?
In addition to compatibility with TOM.processor , the function call from the parent works more or less adequately in the created classes with the help of:
this.__parentCall__( );
And many other little things.
Note: I know that arguments.callee is bad, and it does not work in strict mode , but I haven’t yet come up with a convenient replacement.
Demo page: tredsnet.imtqy.com/TOMGitHub repository: github.com/tredsnet/TOMThe library, of course, is not very prepared for publication, the code is not “cleaned out”, unnecessary comments and notes are not removed, non-standard behavior is possible somewhere
(as it was tested only on our project) . But everything has its time, perhaps in this form the library will be useful to someone, and in the case of the interest of users, development is also possible in the right direction.
Thank you for reading to the end. I would welcome any comments, but please do not forget that the library was created for specific needs, a specific project.