Experimental projects
deborahk / angular-experiments Goto Github PK
View Code? Open in Web Editor NEWExperimental projects
License: MIT License
Experimental projects
License: MIT License
It might be confusing that the WelcomeComponent
is in the home
directory. It would be best to rename home
to welcome
.
Angular-Experiments/apm-refresh/src/app/products/product.ts
Lines 15 to 18 in 446243e
Rather than use the ProductResolved
interface, you could use a discriminated union to get stronger typing and help avoid null references:
export type ProductResolved = {
status: 'resolved';
product: Product;
}
export type ProductError = {
status: 'error';
error: string;
}
export type ProductResponse = ProductResolved | ProductError;
Then you can use ProductResponse
for where you use ProductResolved
. Then in your code, you get better contracts:
checkResponse(productResponse: ProductResponse) {
if (productResponse.status === 'resolved') {
// productResponse is guaranteed to have a product now
this.product = productResponse.product;
return;
}
// productResponse is guaranteed to have an error now
console.error('Something bad happened:', productResponse.error
}
I like to encourage the use of readonly
on properties like this. It makes me feel better when the compiler warns that I tried to change something that shouldn't change.
Angular-Experiments/apm-refresh/src/app/shared/star.component.ts
Lines 1 to 21 in 446243e
This could be entirely me, but I find shared
folders and modules muddy the waters when separating concerns. I suggest moving components to a components
folder and then moving this component to a star
folder in the components folder. This way, we know it is a component and don't need to worry if new components belong in shared
or somewhere else.
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.