Skip to content

Commit

Permalink
fix(docs): singleton - add workaround for #6049 (#6050)
Browse files Browse the repository at this point in the history
Temporary note in our docs to work around #6049

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
eladb authored Mar 25, 2024
1 parent ea40325 commit ad9c114
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/docs/07-examples/80-singletons.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ it or otherwise it creates a new bucket with this id (`as uid`) under the root n
Now, in order to access our bucket from anywhere within the app, I can just use:
```js
let bucket = SingletonBucket.of(this);
class MyFoo {
new() {
let bucket = SingletonBucket.of(this);
}
}
```
And we will always get the same bucket.
> NOTE: if you use `this` in an entrypoint (outside of a class declaration), its type is going to be `Construct`
> (known issue: [#6049](https://github.com/winglang/wing/issues/6049)), so you can use `unsafeCast` as a workaround:
```js
let bucket = SingletonBucket.of(unsafeCast(this));
```

0 comments on commit ad9c114

Please sign in to comment.