Skip to content

Commit bea2b3a

Browse files
authored
feat(almin-logger): Support Transaction#id (#267)
* feat(almin-logger): Support Transaction#id Detect the log is in a transaction by `meta.transaction.id`. It make correct the order output of transaction log. * chore(almin-logger): Update almin-logger example support transaction * test(almin-logger): should create difference logGroup for each transaction
1 parent 1c14f75 commit bea2b3a

File tree

7 files changed

+3535
-16
lines changed

7 files changed

+3535
-16
lines changed

lerna.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"packages": [
1313
"packages/*",
14+
"packages/almin-logger/examples",
1415
"examples/*",
1516
"perf/*"
1617
],

packages/almin-logger/examples/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "counter",
2+
"name": "example-almin-logger-counter",
33
"version": "1.0.0",
44
"description": "Counter example",
55
"private": true,
@@ -18,13 +18,12 @@
1818
"license": "MIT",
1919
"dependencies": {
2020
"almin": "^0.13.0",
21-
"almin-logger": "file:../",
21+
"almin-logger": "^5.0.0",
2222
"react": "^15.0.1",
2323
"react-dom": "^15.0.1",
2424
"uuid": "^2.0.2"
2525
},
2626
"devDependencies": {
27-
"almin": "^0.10.0-1",
2827
"babel-cli": "^6.7.5",
2928
"babel-loader": "^6.2.4",
3029
"babel-plugin-class-display-name": "^2.1.0",

packages/almin-logger/examples/src/component/App.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ const store = new StoreGroup({
1414

1515
const appContext = new Context({
1616
dispatcher,
17-
store
17+
store,
18+
options: {
19+
strict: true
20+
}
1821
});
1922
// setup logging
2023
const logger = new AlminLogger();

packages/almin-logger/examples/src/component/Counter.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ManuallLoggingUseCase from "../usecase/ManuallLoggingUseCase";
99
import ThrowErrorUseCase from "../usecase/ThrowErrorUseCase";
1010
import { Context } from "almin";
1111
import CounterState from "../store/CounterState";
12+
1213
export default class CounterComponent extends React.Component {
1314
constructor(props) {
1415
super(props);
@@ -39,6 +40,22 @@ export default class CounterComponent extends React.Component {
3940
const throwError = () => {
4041
context.useCase(new ThrowErrorUseCase()).execute();
4142
};
43+
const transaction = () => {
44+
context.transaction("+1 -1 +1 +1 = +2", transactionContext => {
45+
return (
46+
Promise.resolve()
47+
.then(() => transactionContext.useCase(new IncrementalCounterUseCase()).execute())
48+
.then(() => transactionContext.useCase(new DecrementalCounterUseCase()).execute())
49+
// add 500ms delay
50+
.then(() => new Promise(resolve => setTimeout(resolve, 500)))
51+
.then(() => transactionContext.useCase(new IncrementalCounterUseCase()).execute())
52+
.then(() => transactionContext.useCase(new IncrementalCounterUseCase()).execute())
53+
.then(() => {
54+
transactionContext.commit();
55+
})
56+
);
57+
});
58+
};
4259
const counterState = this.props.counterState;
4360

4461
return (
@@ -50,6 +67,7 @@ export default class CounterComponent extends React.Component {
5067
<button onClick={parallel}>Counter +- in parallel</button>
5168
<button onClick={manuallLogging}>Manuall Logging</button>
5269
<button onClick={throwError}>Throw Error in UseCase</button>
70+
<button onClick={transaction}>Transaction(+1 -1 +1 +1)</button>
5371
<p>
5472
Count: {counterState.count}
5573
</p>

0 commit comments

Comments
 (0)