function-tree
Advanced tools
Comparing version 0.4.0 to 0.4.1
{ | ||
"name": "function-tree", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "When a function is not enough", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -0,1 +1,19 @@ | ||
function safeStringify(obj) { | ||
var cache = [] | ||
var returnValue = JSON.stringify(obj || {}, function(key, value) { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache.indexOf(value) === -1) { | ||
cache.push(value); | ||
return value; | ||
} | ||
return '[CIRCULAR]' | ||
} | ||
return value; | ||
}); | ||
cache = null; | ||
return returnValue | ||
} | ||
module.exports = function (options) { | ||
@@ -43,3 +61,3 @@ options = options || {} | ||
var event = new CustomEvent('function-tree.client.message', { | ||
detail: JSON.stringify(detail) | ||
detail: safeStringify(detail) | ||
}) | ||
@@ -51,3 +69,3 @@ window.dispatchEvent(event) | ||
var event = new CustomEvent('function-tree.client.message', { | ||
detail: JSON.stringify({ | ||
detail: safeStringify({ | ||
type: type, | ||
@@ -54,0 +72,0 @@ app: APP_ID, |
var chalk = require('chalk') | ||
function safeStringify(obj) { | ||
var cache = [] | ||
var returnValue = JSON.stringify(obj || {}, function(key, value) { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache.indexOf(value) === -1) { | ||
cache.push(value); | ||
return value; | ||
} | ||
return '[CIRCULAR]' | ||
} | ||
return value; | ||
}); | ||
cache = null; | ||
return returnValue | ||
} | ||
module.exports = function (options) { | ||
@@ -106,3 +124,4 @@ options = options || {} | ||
var payloadString = JSON.stringify(payload || {}) | ||
var payloadString = safeStringify(payload) | ||
console.log(padded(chalk.underline.white(functionDetails.name), registeredFunctionTrees[id].logLevel)) | ||
@@ -109,0 +128,0 @@ console.log(padded( |
@@ -5,2 +5,4 @@ # function-tree | ||
`npm install function-tree` | ||
### What is it? | ||
@@ -22,4 +24,6 @@ Readable and maintainable code is a never ending quest. With the increased complexity of modern web applications the execution of code from user interactions and other events in our applications has increased in complexity as well. But this is not only related to the frontend, also our backends has increased execution complexity as our applications are inherently more complex. | ||
More demos coming soon... | ||
`npm run demo:node` | ||
Please contribute with more demos, combining function tree with other projects. | ||
### A small example | ||
@@ -295,2 +299,26 @@ A typical function with side effects. | ||
#### Execute group of functions | ||
By default the function tree executes one function at a time, but you can group them, which basically means the functions will run in parallel. | ||
```js | ||
export default [ | ||
funcA, | ||
[ | ||
funcB, // We run | ||
funcC // in parallel | ||
], | ||
funcD, { | ||
success: [ | ||
funcE, // We run | ||
funcF, // in order | ||
[ | ||
funcG, // But we run in | ||
funcH // parallel again | ||
] | ||
], | ||
error: [] | ||
} | ||
] | ||
``` | ||
#### Passing an initial payload (input) | ||
@@ -551,3 +579,2 @@ ```js | ||
#### NodeDebugger (optional provider) | ||
```js | ||
@@ -571,2 +598,4 @@ const FunctionTree = require('function-tree') | ||
Colors supported are **red, green, yellow, blue, magenta, cyan, white, gray, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan and bgWhite** | ||
#### Events | ||
@@ -573,0 +602,0 @@ The execute function is also an event emitter. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125474
141
3383
624
2