FuseJS can be used in @(UX Markup) through the
FuseJS implements the CommonJS module system. Each code file or inline snippet is a module.
For things inside the module to be visible on the outside, we use the
Failing to export from modules will make it impossible to reach defined data inside the module:
Each code file (or inline snippet) is a module.
To make a module available to other modules through
require, you have to place it in a separate
.js file make sure it is included in the
:Bundle in your
.unoproj, for example like this:
"Includes": [ "MyLibrary/SomeModule.js:Bundle", ...
We can then access this module in any other module in the same project like this:
var myModule = require('MyLibrary/SomeModule');
.jsextension in the
require()string is optional.
You can also use globs to auto-bundle entire folders, e.g.
"Includes": [ "**.js:Bundle" ]
Note that prefixing the file name with a "/" means that we are looking for the file relative to the project root directory. To name a file relative to the current file, prefix with "./". By omitting the prefixes, the file name is relative to the project root, or the global module it's in.
var relativeToProjectRoot = require('/SomeComponent.js'); var relativeFile = require('./MainView.js'); var relativeToRootOrGlobalModule = require('SomeOtherComponent.js');
Design and motivation
The key design goal of FuseJS is to keep your JS code small, clean and only concerned with the practical functions of your application. Meanwhile all things UX-oriented such as layout, data presentation, animation and gesture response is left to declarative UX markup and native UI components.
- Performance - all the performance critical bits are handled in native code and based on native UI components.
- Easy - declarative code is easy to read, write and understand even with limited programming knowledge
- Less error prone - fewer states means less things can go wrong
- Visual tooling - UX markup can be edited by Fuse tools such as inspectors, timelines and generally cool drag & droppy stuff.
If you need to write performance-critical business logic, we recommend doing that in native code or alternatively Uno code instead of JS.