This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ProductComponent implements OnInit { | |
product: Product; | |
constructor(private route: ActivatedRoute) {} | |
ngOnInit() { | |
this.product = this.route.snapshot.data['product']; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BaseProduct { | |
name: string; | |
id: number; | |
price: number; | |
} | |
interface ProductsList { | |
top: BaseProduct[]; | |
bottom: BaseProduct[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BaseProduct { | |
name: string; | |
id: number; | |
price: number; | |
} | |
interface ProductsList { | |
top: BaseProduct[]; | |
bottom: BaseProduct[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('CounterComponent', () => { | |
let component: CounterComponent; | |
let fixture: ComponentFixture<CounterComponent>; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [CounterComponent] | |
}).compileComponents(); | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//testing both success and fail status | |
it('should handle Add to bag Message', () => { | |
const msg: BagResponse = { | |
actionType: 'add', | |
category: 'bag', | |
product: { colorId: '01', productId: '23423', sizeId: 'SM003' }, | |
status: 'success' | |
}; | |
component.chooseMessageHandler(msg); | |
expect(component.bag[0]).toBe(component.buildIdentifier(msg.product)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const DragEvent = (selector:string):Observable<boolean> => { | |
//element where the drag event should be recorded (make sure element is in the dom) | |
const elem = document.querySelector(selector); | |
// touch events to handle mobile devices | |
const touchStart$ = fromEvent<TouchEvent>(elem, 'touchstart'); | |
const touchEnd$ = fromEvent<TouchEvent>(elem, 'touchend'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const romanNumerics = { | |
I: 1, | |
V: 5, | |
X: 10, | |
L: 50, | |
C: 100, | |
D: 500, | |
M: 1000 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fibForLoop = (position: number) => { | |
const result = [0, 1] | |
for (let i = 2; i <= position; i++) { | |
const a = result[i - 1] // first iteration will return 0 , next 1 , 2 , 3 | |
const b = result[i - 2] // first iteration will return 1 , next 2 , 3 , 5} | |
result.push(a + b) | |
} | |
return result[position] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
export interface GenericListProps<T> { | |
items: T[]; | |
itemRenderer: (item: T) => JSX.Element; | |
} | |
export class GenericList<T> extends React.Component<GenericListProps<T>, {}> { | |
render() { | |
const { items, itemRenderer } = this.props; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
interface NameProviderProps { | |
children: (state: NameProviderState) => React.ReactNode; | |
} | |
interface NameProviderState { | |
readonly name: string; | |
} |