Comparing version 2.0.0-next-9f9b97 to 2.0.0-next-c704bc
@@ -7,3 +7,3 @@ # context - Changelog | ||
## 2.0.0 - 2021-11-24 | ||
## 2.0.0 - 2021-12-17 | ||
### Changed or removed | ||
@@ -15,2 +15,3 @@ - 7c43eab major(context): used named export in context (ealush) | ||
### Added | ||
- b0a9a14 feat(vest): use key prop to retain test state after reorder (#732) (Evyatar) | ||
- 220127b added(n4s): partial rule modifier (undefined) | ||
@@ -17,0 +18,0 @@ - b5ce72d feat(n4s): context propagation within enforce (undefined) |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.context = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
@@ -88,2 +88,2 @@ var assign = Object.assign; | ||
}))); | ||
})); |
{ | ||
"version": "2.0.0-next-9f9b97", | ||
"version": "2.0.0-next-c704bc", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "./dist/cjs/context.js", |
@@ -7,2 +7,3 @@ # Context | ||
## How Context Works? | ||
The way context works is quite simple. Creating a context initializes a closure with a context storage object. When you run your context call, it takes your values, and places them in the context storage object. When your function finishes running, the context is cleared. | ||
@@ -129,11 +130,13 @@ | ||
#### But my function is still running. Why did the context clear? | ||
The async parts of your function are actually not executed along with your sync code, and even though you "await" it, the browser carries on and allows other code to run in between instead of blocking execution until your async code is complete. | ||
#### Ok, so what do I do? | ||
There are multiple strategies of handling async functions with context. | ||
1. Pulling your values from context right before your async call | ||
This is the most obvious and easiest to achieve, though not always what you need. The basic idea is that you take whatever you need from the context when it is still available to you. | ||
This is the most obvious and easiest to achieve, though not always what you need. The basic idea is that you take whatever you need from the context when it is still available to you. | ||
2. context.bind or context.run your async function to the context you extracted | ||
This is the next logical step - you have a function that you know should run later with your context. You can bind your context to it for delayed execution. When your function runs later down the line within your asynchronous code, internally it will still have access to whatever you bound to it. | ||
This is the next logical step - you have a function that you know should run later with your context. You can bind your context to it for delayed execution. When your function runs later down the line within your asynchronous code, internally it will still have access to whatever you bound to it. |
22170
141