├── .gitignore
├── .jshintignore
├── .jshintrc
├── AsyncFragmentErrorNode.js
├── AsyncFragmentPlaceholderNode.js
├── AsyncFragmentTimeoutNode.js
├── LICENSE
├── README.md
├── async-fragment-error-tag-transformer.js
├── async-fragment-placeholder-tag-transformer.js
├── async-fragment-tag-transformer.js
├── async-fragment-tag.js
├── async-fragment-timeout-tag-transformer.js
├── async-fragments-tag.js
├── browser.json
├── client-reorder-browser.js
├── client-reorder-runtime.js
├── client-reorder-runtime.min.js
├── client-reorder.js
├── dust
└── index.js
├── marko-taglib.json
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | /work
2 | /build
3 | /.idea/
4 | /npm-debug.log
5 | /node_modules
6 | /*.sublime-workspace
7 | *.orig
8 | .DS_Store
9 | .vscode
10 | coverage
11 |
--------------------------------------------------------------------------------
/.jshintignore:
--------------------------------------------------------------------------------
1 | /client-reorder-runtime.js
2 | /client-reorder-runtime.min.js
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "predef": [
3 |
4 | ],
5 |
6 | "globals": {
7 | "define": true,
8 | "require": true
9 | },
10 |
11 | "node" : true,
12 | "es5" : false,
13 | "browser" : true,
14 | "boss" : false,
15 | "curly": false,
16 | "debug": false,
17 | "devel": false,
18 | "eqeqeq": true,
19 | "evil": true,
20 | "forin": false,
21 | "immed": true,
22 | "laxbreak": false,
23 | "newcap": true,
24 | "noarg": true,
25 | "noempty": false,
26 | "nonew": true,
27 | "nomen": false,
28 | "onevar": false,
29 | "plusplus": false,
30 | "regexp": false,
31 | "undef": true,
32 | "sub": false,
33 | "white": false,
34 | "eqeqeq": false,
35 | "latedef": true,
36 | "unused": "vars",
37 | "strict": false,
38 |
39 | /* Relaxing options: */
40 | "eqnull": true
41 | }
42 |
--------------------------------------------------------------------------------
/AsyncFragmentErrorNode.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 eBay Software Foundation
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | 'use strict';
17 | function AsyncFragmentErrorNode(props) {
18 | AsyncFragmentErrorNode.$super.call(this, 'async-fragment-error');
19 | if (props) {
20 | this.setProperties(props);
21 | }
22 | }
23 |
24 | AsyncFragmentErrorNode.nodeType = 'element';
25 |
26 | AsyncFragmentErrorNode.prototype = {
27 | doGenerateCode: function (template) {
28 | throw new Error('Illegal State. This node should have been removed');
29 | }
30 | };
31 |
32 | module.exports = AsyncFragmentErrorNode;
33 |
--------------------------------------------------------------------------------
/AsyncFragmentPlaceholderNode.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 eBay Software Foundation
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | 'use strict';
17 | function AsyncFragmentPlaceholderNode(props) {
18 | AsyncFragmentPlaceholderNode.$super.call(this, 'async-fragment-placeholder');
19 | if (props) {
20 | this.setProperties(props);
21 | }
22 | }
23 |
24 | AsyncFragmentPlaceholderNode.nodeType = 'element';
25 |
26 | AsyncFragmentPlaceholderNode.prototype = {
27 | doGenerateCode: function (template) {
28 | throw new Error('Illegal State. This node should have been removed');
29 | }
30 | };
31 |
32 | module.exports = AsyncFragmentPlaceholderNode;
--------------------------------------------------------------------------------
/AsyncFragmentTimeoutNode.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 eBay Software Foundation
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | 'use strict';
17 | function AsyncFragmentTimeoutNode(props) {
18 | AsyncFragmentTimeoutNode.$super.call(this, 'async-fragment-timeout');
19 | if (props) {
20 | this.setProperties(props);
21 | }
22 | }
23 |
24 | AsyncFragmentTimeoutNode.nodeType = 'element';
25 |
26 | AsyncFragmentTimeoutNode.prototype = {
27 | doGenerateCode: function (template) {
28 | throw new Error('Illegal State. This node should have been removed');
29 | }
30 | };
31 |
32 | module.exports = AsyncFragmentTimeoutNode;
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 JS Foundation and contributors
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | marko-async
2 | =====================
3 |
4 | ----------------
5 |
6 | :heavy_exclamation_mark: The source code and documentation in this repo are only relevant to Marko v2. For Marko v3, this repo has been merged into the main [marko](https://github.com/marko-js/marko) repo.
7 |
8 | - Marko v3 async taglib docs: http://markojs.com/docs/marko/language-guide/#async-taglib
9 | - Marko v3 async taglib source code: [marko/taglibs/async](https://github.com/marko-js/marko/tree/master/taglibs/async)
10 |
11 | ----------------
12 |
13 | The `marko-async` taglib provides support for the more efficient and simpler "Pull Model "approach to providing templates with view model data.
14 |
15 | * __Push Model:__ Request all needed data upfront and wait for all of the data to be received before building the view model and then rendering the template.
16 | * __Pull Model:__ Pass asynchronous data provider functions to template immediately start rendering the template. Let the template _pull_ the data needed during rendering.
17 |
18 | The Pull Model approach to template rendering requires the use of a templating engine that supports asynchronous template rendering (e.g. [marko](https://github.com/marko-js/marko) and [dust](https://github.com/linkedin/dustjs)). This is because before rendering the template begins not all of data may have been fully retrieved. Parts of a template that depend on data that is not yet available are rendered asynchronously with the Pull Model approach.
19 |
20 | # Push Model versus Pull Model
21 |
22 | The problem with the traditional Push Model approach is that template rendering is delayed until _all_ data has been fully received. This reduces the time to first byte, and it also may result in the server sitting idle while waiting for data to be loaded from remote services. In addition, if certain data is no longer needed by a template then only the template needs to be modified and not the controller.
23 |
24 | With the new Pull Model approach, template rendering begins immediately. In addition, fragments of the template that depend on data from data providers are rendered asynchronously and wait only on the associated data provider to complete. The template rendering will only be delayed for data that the template actually needs.
25 |
26 | # Example
27 |
28 | ```javascript
29 | var template = require('./template.marko');
30 |
31 | module.exports = function(req, res) {
32 | var userId = req.query.userId;
33 | template.render({
34 | userProfileDataProvider: function(callback) {
35 | userProfileService.getUserProfile(userId, callback);
36 | }
37 | }, res);
38 | }
39 | ```
40 |
41 | ```html
42 |
46 |
56 |
57 |
65 |
66 | ```html
67 |
72 |
82 |
83 |
127 |
130 |
131 |
147 |
150 |
166 |
169 |