1 | Chiχ Loader
|
2 | =========
|
3 |
|
4 | [![Build Status](https://travis-ci.org/psichi/chix-loader.png)](https://travis-ci.org/psichi/chix-loader)
|
5 |
|
6 | This is the base component loader for Chiχ.
|
7 |
|
8 | Chiχ uses node definitions to describe each of it's components.
|
9 |
|
10 | The loader takes care of loading these definitions and caching them.
|
11 |
|
12 | On top of the base loaders there are loaders which load the definitions from
|
13 | a remote server or from the file system.
|
14 |
|
15 | The base loader accepts definitions added manually.
|
16 |
|
17 | Definitions are indexed by provider url, but the manual loader uses '@' to indicate
|
18 | the definitions are local.
|
19 |
|
20 | Example usage:
|
21 | ```javascript
|
22 |
|
23 | var Loader = require('chix-loader');
|
24 |
|
25 | var loader = new Loader();
|
26 |
|
27 | loader.addNodeDefinitions('@', [{
|
28 | ns: 'my', name: 'component',
|
29 | ports: {
|
30 | input: {
|
31 | 'in': {
|
32 | type: 'string'
|
33 | }
|
34 | },
|
35 | output: {
|
36 | out: {
|
37 | type: 'string'
|
38 | }
|
39 | }
|
40 | }
|
41 | }, {
|
42 | ns: 'my', name: 'component2',
|
43 | ports: { input: { in: { type: 'string' } } }
|
44 | }]);
|
45 |
|
46 | // retrieve a node definitions from a provider
|
47 | loader.getNodeDefinitionFrom('@', 'my', 'component');
|
48 |
|
49 | // Checks whether the definition is available
|
50 | loader.hasNodeDefinition('@', 'my', 'component'); // true
|
51 |
|
52 | // Given a node and it's map, will try and load the (remote) node.
|
53 | // TODO: Explain provider structure within a map
|
54 | loader.getNodeDefinition({
|
55 | ns: 'my',
|
56 | name: 'component'
|
57 | }, map);
|
58 |
|
59 | ```
|
60 |
|
61 | # collecting dependencies
|
62 |
|
63 | It's also the loaders job to collect the dependencies needed to run a graph.
|
64 | This is rather simple if a graph only contains non-composite nodes, but quickly
|
65 | becomes more complex when subgraphs are used and the number of subgraphs are unknown.
|
66 | The loader keeps track of which requires are needed.
|