trademe / ensure Goto Github PK
View Code? Open in Web Editor NEWUtility decorators for Trade Me
Utility decorators for Trade Me
If you use a string value enum with the isEnum guard it returns the key name rather than the enum value :(
Maz with Ben
enum Foo {
aaa = 'AAA'
}
let v = isEnum(Foo)('aaa', 'someprop');
assert(v, 'AAA'); // fails as isEnum returns 'aaa'
isNotNull
is currently special-cased to only run on get. Can we support marking custom value guard functions to run on get?
An attribute would be petty cool, e.g.
import { Guard } from '@trademe/ensure';
@Guard({ onGet: true })
function myGuard () {
...
}
Since the isNumber
value guard uses +
to convert a string to a number, this has the side-effect of treating a whitespace-only or empty string as zero. E.g. +' '
resolves to 0
.
This should probably be treated as an error case. Using parseInt(..., 10)
instead should resolve this.
Can we make the _reset()
method differently available, so it's more easily accessible in unit testing?
E.g.: I would like to be able to do something like this:
afterEach(() => {
// Reset for @Singleton
let classUnderTest = (<any>CardViewModeService);
classUnderTest._reset();
});
But currently, calling TestBed.Get()
in afterEach
to retrieve it is creating a new instance of the class under test - as I'm unable to reset on the instance.
Craig suggested something more like:
var foo = function singleton() {
if (!instantiated) {
checkInjectable(injectable);
instantiated = true;
foo._reset = function () { return instantiated = false; };
return injectable.apply(this, arguments);
}
throw new ensure_error_1.EnsureError("\n " + injectable.name + " is a singleton and must not be instantiated multiple times.\n ");
};
return foo;
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.