10000 Fix casing of variables in docs by willrowe · Pull Request #852 · twigjs/twig.js · GitHub
[go: up one dir, main page]

Skip to content

Fix casing of variables in docs #852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions ASYNC.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Twig.async.forEach(arr, function(value, index) {

## Switching render mode

The rendering mode of Twig.js internally is determined by the `allow_async` argument that can be passed into `Twig.expression.parse`, `Twig.logic.parse`, `Twig.parse` and `Twig.Template.render`. Detecting if at any point code runs asynchronously is explained in [detecting asynchronous behaviour](#detecting-asynchronous-behaviour).
The rendering mode of Twig.js internally is determined by the `allowAsync` argument that can be passed into `Twig.expression.parse`, `Twig.logic.parse`, `Twig.parse` and `Twig.Template.render`. Detecting if at any point code runs asynchronously is explained in [detecting asynchronous behaviour](#detecting-asynchronous-behaviour).

For the end user switching between synchronous and asynchronous is as simple as using a different method on the template instance.

Expand Down Expand Up @@ -157,10 +157,10 @@ var template = twig({

The pattern used to detect asynchronous behaviour is the same everywhere it is used and follows a simple pattern.

1. Set a variable `is_async = true`
1. Set a variable `isAsync = true`
2. Run the promise chain that might contain some asynchronous behaviour.
3. As the last method in the promise chain set `is_async = false`
4. Underneath the promise chain test whether `is_async` is `true`
3. As the last method in the promise chain set `isAsync = false`
4. Underneath the promise chain test whether `isAsync` is `true`

This pattern works because the last method in the chain will be executed in the next run of the eventloop (`setTimeout`/`setImmediate`).

Expand All @@ -169,7 +169,7 @@ This pattern works because the last method in the chain will be executed in the
**Synchronous promises only**

```javascript
var is_async = true;
var isAsync = true;

Twig.Promise.resolve()
.then(function() {
Expand All @@ -178,10 +178,10 @@ Twig.Promise.resolve()
return 'hello world';
})
.then(function() {
is_async = false;
isAsync = false;
});

if (is_async)
if (isAsync)
console.log('method ran asynchronous');

console.log('method ran synchronous');
Expand All @@ -195,18 +195,18 @@ console.log('method ran synchronous');
**Mixed promises**

```javascript
var is_async = true;
var isAsync = true;

Twig.Promise.resolve()
.then(function() {
// We run our work in here such to allow for asynchronous work
return Promise.resolve('hello world');
})
.then(function() {
is_async = false;
isAsync = false;
});

if (is_async)
if (isAsync)
console.log('method ran asynchronous');

console.log('method ran synchronous');
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var Twig = require("twig"),

// This section is optional and used to configure twig.
app.set("twig options", {
allow_async: true, // Allow asynchronous compiling
allowAsync: true, // Allow asynchronous compiling
strict_variables: false
});

Expand Down
0