Skip to content

Commit

Permalink
feat(docs): update docs
Browse files Browse the repository at this point in the history
Updates the Wing docs. See details in [workflow run].

[Workflow Run]: https://github.com/winglang/docsite/actions/runs/5567998985

------

*Automatically created via the "update-docs" workflow*

Signed-off-by: monabot <[email protected]>
  • Loading branch information
monadabot committed Jul 16, 2023
1 parent d05490b commit bcf3933
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
40 changes: 17 additions & 23 deletions versioned_docs/version-latest/02-concepts/03-compile-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,33 @@ There might be times when you need to write code that is specific to a compiler

With the Wing `util` library, you can access environment variables. The `WING_TARGET` environment variable contains the current compiler target, which you can use to conditionally run target-specific code. See the example below:

```js
```js playground
bring cloud;
bring util;

let bucket = new cloud.Bucket();
let counter = new cloud.Counter();
let invocationCounter = new cloud.Counter();
let queue = new cloud.Queue();

queue.setConsumer(inflight (msg: str) => {
let i = counter.inc();
bucket.put("file-${i}.txt", msg);
invocationCounter.inc();
});

// only create this verbose logger if our Wing target is sim
if util.env("WING_TARGET") == "sim" {
let verboseLogger = new cloud.Service(
onStart: inflight() => {
// Continuously log the files in the bucket every 10 seconds
while true {
util.sleep(10s);
log("Files in bucket");
log("==================");
for f in bucket.list() {
log(f);
}
log("===================");
}
}
);
}
new cloud.Function(inflight ()=> {
// push a message to queue
queue.push("m");
// sleep according to target
if util.env("WING_TARGET") == "sim" {
log("Running on Simulator, sleeping for 1s");
util.sleep(1s);
} else {
log("Running on the cloud, sleeping for 30s");
util.sleep(30s);
}
log("Function invoked ${invocationCounter.peek()} times");
});
```

In this example, we're creating a verbose logger service only when the `WING_TARGET` environment variable is set to "sim". The `onStart` function of this service lists the files in the bucket and logs them every 10 seconds.
In this example, we want to sleep briefly for the Simulator target and for 30 seconds for cloud targets, this is achieved using the `WING_TARGET` environment variable.

## Compiler plugins

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords: [Wing example]

```ts
let x = 12;
x = 77; // ERROR: x is non reassignable
x = 77; // error: Variable is not reassignable

let var y = "hello";
y = "world"; // OK (y is reassignable)
Expand All @@ -31,7 +31,7 @@ x1 = nil; // ERROR: Expected type to be "str", but got "nil" instead
x3 = nil; // OK (x3 is optional)
```
### Scopes
```ts playground
```ts
let s = "parent";
log(s); // prints parent
if true {
Expand Down
8 changes: 4 additions & 4 deletions versioned_docs/version-latest/07-examples/02-primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords: [Wing example]

## Str
### Concat and Interpolate
```ts playground
```ts
let s1 = "Hello Wing String";
log(s1); // prints Hello Wing String
let s2 = "Interpolate: ${s1}"; // string interpolation
Expand All @@ -17,7 +17,7 @@ log(s3); // prints Concat: Hello Wing String
```

### Str methods
```ts playground
```ts
let s = "Hello to a new Wing world";

// lets start with split
Expand Down Expand Up @@ -45,7 +45,7 @@ for w in s.split(" ") {

## Num

```ts playground
```ts
let n1 = 10;
log("${n1}"); // 10

Expand All @@ -68,7 +68,7 @@ log("${n6}"); // The meaning of the universe

## Bool

```ts playground
```ts
let b1 = true;
let b2 = false;

Expand Down
2 changes: 1 addition & 1 deletion versioned_docs/version-latest/07-examples/03-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let handler = inflight (message: str): void => {
// code
};
// inflight modifier is not required when function is declared in inflight context
let dup = (s: str, count: num): str => {
let sup = (s: str, count: num): str => {
// code
};
};
Expand Down

0 comments on commit bcf3933

Please sign in to comment.