Component Initialization
defineComponent
Description
: defineComponent({Object}propertiesAndMethods)
Explanation
:
Method. A shortcut to define components. Refer to Component Definition for details.
Usage
:
1 | var MyApp = san.defineComponent({ |
compileComponent
Version
: >= 3.3.0 & < 3.9.0
Description
: {void} compileComponent({Function}ComponentClass)
Explanation
:
Method. Compile a component. The compilation mainly consists of parsing the template into ANodes and call .defineComponent()
for plain object within the component.
Components will compile automatically on its first instantiation. Typically you won’t need to call this API to compile components manually, but it’s provided anyway in case you need ahead-of-time compilation.
Usage
:
1 | var MyApp = san.defineComponent({ |
Component
Type
: Function
Explanation
:
Property. The component class, from which the newly defined components will inherit. For most cases the san.defineComponent method should be used instead. Refer to Component Definition for details.
Usage
:
1 | import {Component} from 'san'; |
inherits
Description
: inherits({Function}SubClass, {Function}SuperClass)
Explanation
:
Method. An util method to implement inheritance, which is the case when defining components (inherit from san.Component). Usually, to define a component we use san.defineComponent in ES5 and extends in ESNext.
It is not recommended to use .inherits()
in most cases. Refer to Component Definition for details.
Server-Side Rendering
compileToRenderer
Version
:>= 3.1.0
Description
: {function(Object):string} compileToRenderer({Function}ComponentClass)
Explanation
:
Method. Compile a component class into a renderer method. Refer to Server-Side Rendering for details.
Usage
:
1 | var MyApp = san.defineComponent({ |
compileToSource
Version
:>= 3.1.0
Description
: {string} compileToRenderer({Function}ComponentClass)
Explanation
:
Method. Compile a component class into a source file containing the renderer method. Refer to Server-Side Rendering for details.
Usage
:
1 | var MyApp = san.defineComponent({ |
Template Compilation
ExprType
Version
:>= 3.0.3
Type
: Object
Explanation
:
Property. An enum value representing the expression type, which helps to understand and use the compile output produced by San. Refer to ANode for details.
parseExpr
Version
:>= 3.0.3
Description
: {Object} parseExpr({string}source)
Explanation
:
Method. Parse the source string into an expression object. Refer to ANode for details.
Usage
:
1 | var expr = san.parseExpr('!user.isLogin'); |
parseTemplate
Version
:>= 3.0.3
Description
: {ANode} parseTemplate({string}source)
Explanation
:
Method. Parse the source string into an ANode object. The San template engine can be reused via this method. Refer to ANode for details.
Usage
:
1 | var aNode = san.parseTemplate('<p>Hello {{name}}!</p>'); |
parseComponentTemplate
Version
: >= 3.9.0
Description
: {ANode} parseComponentTemplate({Function}ComponentClass)
Explanation
:
Method. Parse component template into ANode objects. Different from parseTemplate
, this method extracts the first child node, attaches id/style/class
attributes to it, and returns it as the root. Basically, parseComponentTemplate
parses the template the same way as san parses component in runtime.
Usage
:
1 | var MyComponent = san.defineComponent({ |
Data
Data container and expression evaluator in San components are also exposed. These classes can be useful to handle component-independent data such as application state.
Data
Version
:>= 3.5.6
Type
: Class Function
Explanation
:
Data Container provides get, set, splice, push, pop, unshift, shift, merge and apply methods. Refer to Data Manipulation for details.
change
event is fired when the data is changed via data manipulation methods. Handlers for the change
event can be registered and unregistered via listen
and unlisten
methods respectively.
1 | var data = new san.Data({ |
evalExpr
Version
:>= 3.5.6
Description
: {*} evalExpr({Object}expr, {Data}data, {Component=}owner)
Explanation
:
Method. evalExpr
is used to evaluate the value of an expression.
expr
can be obtained via parseExpr method. For the supported expression types, refer to Expressiondata
can be either component’s data object, or any data object obtained by new Dataowner
is used for evaluating filters in the expression, required when there’re custom filters in the expression, optional otherwise.
1 | var data = new san.Data({ |
Others
debug
Type
: boolean
Explanation
:
Property. Whether or not to enable debug functionalities. Before using Chrome DevTools to debug your San application, make sure the following conditions are matched:
- the debug property of San module is set to true
- the San loaded in the current page is built with DevTools functionality. Refer to San releases for details
version
Type
: string
Explanation
:
Property. The San version number.
LifeCycle
Version
: < 3.3.0 (deprecated)
Type
: Function
Explanation
:
Property. Lifecycle Class is useful when you need to render and update components manually.
LifeCycle defines the following lifecycle states, some of which are mutually exclusive. In detail:
1 | { |
The current state can be set via the .set()
method of LifeCycle class, and can be tested via the is
method.
Usage
:
1 | var lifeCycle = new san.LifeCycle(); |