Skip to content

Instantly share code, notes, and snippets.

View anthanh's full-sized avatar
👾
Cooking some magic stuff

Anthanh anthanh

👾
Cooking some magic stuff
View GitHub Profile
{
"data": [
"http://www.homerswebpage.com/",
"https://etereo.io/"
]
}
storiesOf('my-front/UI/Button', module)
.add('Button', () => <ButtonsSet />)
.add('Button Link', () => (
<>
<Button
variant="contained"
component="a"
href="https://google.es"
target="_blank"
describe('On submit form', () => {
it('the popover is rendered', async () => {
const store = createStore()
const { container, getByText, getByTestId } = render(
<ReduxProvider store={store}>
<CheckCoverageContainer />
</ReduxProvider>
)
describe('<PriceCard />', () => {
it('renders <PriceCard /> component', async () => {
const { container } = render(
<PriceCard data={mockData} onAddToCart={() => {}} />
)
expect(container).toMatchSnapshot()
})
})
describe('formatNumber function', () => {
it('works with strings', () => {
const formatted = formatNumber('12.45')
expect(formatted).toEqual('12,45')
})
it('works with numbers', () => {
const formatted = formatNumber(12.45)
@anthanh
anthanh / regex.js
Created November 25, 2018 22:56
angular ssr rendered styles regex
const stylesRegexp = /<style ng-transition="thor">(.*?(\n))+.*?<\/style>/g
@anthanh
anthanh / app.component.ts
Last active December 12, 2017 23:38
Angular 5 with Universal and TransferState: TransferState Support
// app.component.ts
...
import { TransferState, makeStateKey } from '@angular/platform-browser';
const PHOTOS = makeStateKey('photos');
@Component({...})
export class AppComponent implements OnInit {
opened: boolean;
photos: any[];
{
"name": "angular-universal-example",
...
"scripts": {
"ng": "ng",
"start": "ng serve",
"start:ssr": "node dist/server.js",
"build": "run-s build:client build:aot build:server",
"build:client": "ng build -prod --build-optimizer --app 0",
"build:aot": "ng build --aot --app 1",
@anthanh
anthanh / webpack.config.ts
Last active December 12, 2017 23:32
Angular 5 with Universal and TransferState: Webpack config
// webpack.config.ts
const path = require('path');
var nodeExternals = require('webpack-node-externals');
module.exports = {
entry: {
server: './src/server.ts'
},
resolve: {
extensions: ['.ts', '.js'],
@anthanh
anthanh / server.ts
Created December 10, 2017 23:29
Angular 5 with Universal and TransferState: Express app
// server.ts
import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import * as express from 'express';
import { join } from 'path';
import { readFileSync } from 'fs';
enableProdMode();