2.6.3 • Published 5 years ago

done-autorender v2.6.3

Weekly downloads
136
License
MIT
Repository
github
Last release
5 years ago

Build Status npm version Greenkeeper badge

done-autorender

Automatically renders a template, either to the <html> or <body> elements.

Install

Install with NPM and use with StealJS:

npm install done-autorender --save

Use

done-autorender enables you to use a Stache template as your application entry-point (the main). done-autorender will wait for your page to be fully loaded (including all dependencies) and then will insert the template into the <head> and <body>. For example:

index.stache

<html>
<head>
  <title>My Site</title>
</head>
<body>
  <can-import from="~/main.css"/>
  <can-import from="~/routes"/>
  <can-import from="~/state" export-as="viewModel"/>

  {{#eq page "home"}}

    <can-dynamic-import from="~/home/">
      {{#if isResolved}}
        <home-page></home-page>
      {{/if}}
    </can-dynamic-import>

  {{/eq}}
</body>
</html>

index.html

<script src="node_modules/steal/steal.js"
	main="app/index.stache!done-autorender"></script>

Then load index.html in a browser. After all dependencies are loaded your index.stache will be rendered and inserted into the page.

No Zone option

If you do not use SSR but still want to use done-autorender to bootstrap your application you can use the no-zone module:

<script src="node_modules/steal/steal.js"
	main="app/index.stache!done-autorender/no-zone"></script>

API

ViewModel

Each done-autorender application is backed by a View Model (such as a DefineMap) that represents the state of the entire application.

To import this View Model into your application use a can-import tag like so:

<can-import from="app/state" export-as="viewModel" />

This tells done-autorender that the module app/state is the ViewModel.

Debugging

In development mode, can-zone/debug is enabled to provide debugging information in the case where the Zone times out and the app is never attached to the page.

You can control the timeout by setting the data-autorender-timeout attribute on the steal script tag (note that data- is optional here) like so:

<script src="./node_modules/steal/steal.js"
	data-autorender-timeout="1000"></script>

The timeout is specified in milliseconds; in the above example it is 1 second. By default the zone will timeout after 5000 milliseconds (5 seconds).

After the Zone has timed out the console will print out stack traces of code that failed to complete. Use these stack traces to figure out what caused reattachment to fail and fix anything that can be fixed (by, for example, using Zone.ignore). These information looks like:

debug stack traces

Break on timeout

Additionally you can choose to have a debugger; breakpoint that is hit after the Zone times out. This allows you to more easily figure out which code is still running and see if something can be done about it.

Enable this by setting the data-autorender-debug-break option on the steal script tag like so:

<script src="./node_modules/steal/steal.js"
	data-autorender-debug-break></script>

This is a boolean attribute and doesn't need a value. Instead of logging stack traces you will get a breakpoint from which you can look back in the call stack and inspect the reason why the code continued to run past the timeout.

break on timeout

can-view-model

If you install can-view-model you can use it to access the Application ViewModel like so:

var canViewModel = require("can-view-model");

var appVM = canViewModel(document.documentElement);

Keeping elements in the DOM

By default done-autorender removes all elements from the <head> and <body> and replaces them with the elements from the template. This is to facilitate use with done-ssr which will have duplicated content.

Some times, especially if not using done-ssr, you might want to keep some elements that are in your HTML but not your stache template. Use the data-keep property and done-autorender will leave them alone:

<html>
<head>
  <meta name="some-prop" content="some-value" data-keep>
</head>
</html>
3.0.0-pre.1

5 years ago

3.0.0-pre.0

5 years ago

2.6.3

5 years ago

2.6.2

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.8

5 years ago

2.5.7

5 years ago

2.5.6

5 years ago

2.5.5

5 years ago

2.5.4

5 years ago

2.5.3

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

2.0.0-pre.14

6 years ago

2.0.0-pre.13

6 years ago

2.0.0-pre.12

6 years ago

2.0.0-pre.11

6 years ago

2.0.0-pre.10

6 years ago

2.0.0-pre.8

6 years ago

2.0.0-pre.7

6 years ago

2.0.0-pre.6

6 years ago

1.5.2

6 years ago

2.0.0-pre.5

6 years ago

2.0.0-pre.4

6 years ago

1.5.1

6 years ago

2.0.0-pre.2

6 years ago

2.0.0-pre.1

6 years ago

2.0.0-pre.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.4.0-beta.0

6 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.3.0-beta.3

7 years ago

1.3.0-beta.2

7 years ago

1.3.0-beta.1

7 years ago

1.3.0-beta.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

1.0.0-alpha.9

7 years ago

1.0.0-alpha.8

7 years ago

1.0.0-alpha.7

7 years ago

1.0.0-alpha.6

7 years ago

1.0.0-alpha.5

7 years ago

1.0.0-alpha.4

7 years ago

1.0.0-alpha.3

7 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago

1.0.0-alpha.0

7 years ago

0.9.0-pre.3

7 years ago

0.9.0-pre.2

7 years ago

0.9.0-pre.1

8 years ago

0.9.0-pre.0

8 years ago

0.8.0

8 years ago

0.7.3

8 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.3

8 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.6.0-pre.0

8 years ago

0.5.0

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.2.0-pre.0

9 years ago

0.1.0-pre.2

9 years ago

0.1.0-pre.1

9 years ago

0.1.0-pre.0

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago