Last active
December 11, 2018 04:40
-
-
Save oychao/81a2128ca2196182e8b6dcd83cd9a4dd to your computer and use it in GitHub Desktop.
learn react and vue
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
/** | |
* Test React's Transaction | |
* <pre> | |
* wrappers (injected at creation time) | |
* + + | |
* | | | |
* +-----------------|--------|--------------+ | |
* | v | | | |
* | +---------------+ | | | |
* | +--| wrapper1 |---|----+ | | |
* | | +---------------+ v | | | |
* | | +-------------+ | | | |
* | | +----| wrapper2 |--------+ | | |
* | | | +-------------+ | | | | |
* | | | | | | | |
* | v v v v | wrapper | |
* | +---+ +---+ +---------+ +---+ +---+ | invariants | |
* perform(anyMethod) | | | | | | | | | | | | maintained | |
* +----------------->|-|---|-|---|-->|anyMethod|---|---|-|---|-|--------> | |
* | | | | | | | | | | | | | |
* | | | | | | | | | | | | | |
* | | | | | | | | | | | | | |
* | +---+ +---+ +---------+ +---+ +---+ | | |
* | initialize close | | |
* +-----------------------------------------+ | |
* </pre> | |
*/ | |
const Transaction = require('../Transaction.js'); | |
const wrappers = [{ | |
initialize() { | |
console.log(`wrapper 1: ${this.name} initialize`); | |
}, | |
close() { | |
console.log(`wrapper 1: ${this.name} close`); | |
} | |
}, { | |
initialize() { | |
console.log(`wrapper 2: ${this.name} initialize`); | |
}, | |
close() { | |
console.log(`wrapper 2: ${this.name} close`); | |
} | |
}]; | |
function MyTransaction() { | |
this.reinitializeTransaction(); | |
this.name = 'Ouyang'; | |
} | |
Object.assign(MyTransaction.prototype, Transaction, { | |
getTransactionWrappers() { | |
return wrappers; | |
} | |
}); | |
const myTransaction = new MyTransaction(); | |
const ret = myTransaction.perform(function(a, b) { | |
console.log(`performing: ${this.name} is calculating: a + b = ${a + b}`); | |
return a + b; | |
}, myTransaction, 1, 2); | |
console.log(`the result is ${ret}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment