Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
effects-as-data
Advanced tools
A micro abstraction layer for Javascript that makes writing, testing, and monitoring side-effects easy.
const { promisify } = require("util");
const fs = require("fs");
const readFile = promisify(fs.readFile);
const logger = require("logger");
async function getResource(id) {
const time = Date.now();
const resource = await http.get(
`http://example.com/resource/${id}?cache=${time}`
);
return getResource;
}
module.exports = {
getResource
};
This is a drop-in replacement written using effects-as-data
:
const { promisify, cmds } = require("effects-as-data");
const http = require("effects-as-data-http");
function* getResource(id) {
const time = yield cmds.now();
const resource = yield http.get(
`http://example.com/resource/${id}?cache=${time}`
);
return getResource;
}
module.exports = {
getResource: promisify(getResource)
};
What normally requires mocks, spies, and other tricks for unit testing, effects-as-data
does simply and declaratively. The tests below tests all code branches in the function, tests the order in which side-effects occur and tests that everything is called the expected number of times and with the expected arguments:
const { testFn, args } = require("effects-as-data/test");
const { promisify, cmds } = require("effects-as-data");
const http = require("effects-as-data-http");
const testGetResource = testFn(getResource);
test(
"getResource() should do an http get request and return the resource",
testGetResource(() => {
const id = "123";
const time = 23456;
const resource = { foo: "bar" };
return args(id)
.cmd(cmds.now())
.result(time)
.cmd(http.get(`http://example.com/resource/${id}?cache=${time}`))
.result(resource)
.returns(resource);
})
);
Generators are much more powerful than async/await
because generators allow developers to handle Javascript's most difficult problems all in one construct: asynchronous operations, non-determinism (ex: Date.now()
), and eliminate in most code the use of globals, singletons, closures for state, dependency injection, brittle promise chains, and mocks/spies. Generators, when used in effects-as-data
, allow developers to eliminate the anti-patterns that make Javascript hard to write, maintain and test.
FAQs
A micro abstraction layer for Javascript that makes writing, testing, and monitoring side-effects easy.
The npm package effects-as-data receives a total of 8 weekly downloads. As such, effects-as-data popularity was classified as not popular.
We found that effects-as-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.