-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: 📝 tracking example, additions to readme
- Loading branch information
Showing
6 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { sessionRef, container } from './service.js' | ||
import crypto from 'crypto' | ||
|
||
container.addScoped(() => crypto.randomUUID(), sessionRef) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { TrackingContainer } from 'symboldi/tracking' | ||
|
||
// empty container | ||
export const container = new TrackingContainer() | ||
|
||
// define ref for session | ||
export const sessionRef = TrackingContainer.ref<string>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { container, sessionRef } from './service.js' | ||
import './register.js' | ||
|
||
// get first session | ||
const firstSession = container.get(sessionRef) | ||
let secondSession = "" | ||
|
||
container.run(()=>{ | ||
// get a second session, inside the run callback | ||
secondSession = container.getOrFail(sessionRef) | ||
}) | ||
|
||
// get a third session, outside the run callback | ||
const thirdSession = container.getOrFail(sessionRef) | ||
|
||
/** | ||
* firstSession and thirdSession matches, secondSession is different | ||
* ceff046e-ceb0-456e-875b-3010792e1294 dbe8fd2e-99c4-4f03-b57e-b930a90249f2 ceff046e-ceb0-456e-875b-3010792e1294 | ||
*/ | ||
console.log(firstSession, secondSession, thirdSession) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters