Skip to content

Instantly share code, notes, and snippets.

View tomastrajan's full-sized avatar
🍰
Where is the cake?

Tomas Trajan tomastrajan

🍰
Where is the cake?
View GitHub Profile
@tomastrajan
tomastrajan / ampe-mutate.ts
Created May 1, 2017 09:54
Angular Model Pattern - model mutation
@Injectable()
export class TodosService {
/* ... */
// pass all neccessary data as funcion parameters
toggleTodo(name: string) {
// retrieve model internal state
const todos = this.model.get();
@tomastrajan
tomastrajan / ampe-component-mutatet.ts
Created May 1, 2017 09:59
Angular Model Pattern - component service call
export class TodosComponent {
/* ... */
onTodoToggleClick(todo: Todo) {
this.todosService.toggleTodo(todo.name);
}
}
@tomastrajan
tomastrajan / ampe-component-subscription.ts
Last active May 1, 2017 10:32
Angular Model Pattern - component state subscription
@Component({
selector: 'todos',
template: `
<!--
accessing multiple properties,
we're better off subscribing only once in component's ngOnInit()
-->
Done todos: {{count.done}}
Remaining todos: {{count.remaining}}
All todos: {{count.all}}
@tomastrajan
tomastrajan / style.scss
Last active May 31, 2017 13:38
Angular Material Theming - custom components
@import '~@angular/material/theming';
@include mat-core();
@import 'my-theme.scss';
// import custom componenet themes
// unofficial naming convention to support nice ordering of files in IDE
// to see theme under the original style file of the componenent
@import 'app/shared/big-input/big-input.component.scss-theme';
@tomastrajan
tomastrajan / big-input-component.scss-theme.scss
Last active November 29, 2018 05:46
Angular Material Theming - custom component theme
@import '~@angular/material/theming';
// mixin name will be used in main style.scss
@mixin big-input-component-theme($theme) {
// retrieve variables from theme
// (all possible variables, use only what you really need)
$primary: map-get($theme, primary);
$accent: map-get($theme, accent);
$warn: map-get($theme, accent);
@tomastrajan
tomastrajan / some-lib.js
Created May 10, 2019 16:53
Angular Library Build Output
import { Injectable, Component, NgModule, defineInjectable } from '@angular/core';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var SomeLibService = /** @class */ (function () {
function SomeLibService() {
}
SomeLibService.decorators = [
@tomastrajan
tomastrajan / change-mac.sh
Created May 20, 2019 12:11
BASH CHANGE MAC by Minko
function changeMac() {
local mac=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
sudo ifconfig en0 ether $mac
sudo ifconfig en0 down
sudo ifconfig en0 up
echo "Your new physical address is $mac"
}
@tomastrajan
tomastrajan / ampe-combine-state.ts
Created May 1, 2017 11:08
Angular Model Pattern - combine state from multiple models
/* session and clients models in some component or service */
const filteredClients$ = this.sessionService.session$
.combineLatest(this.clientService.clients$)
.map(([session, clients]) => clients.filter(client => {
if (client.vip && session.accessVips) {
return true;
} else if (!client.vip) {
return true;
}
@tomastrajan
tomastrajan / ampe-resolve.ts
Last active September 16, 2019 04:58
Angular Model Pattern - initialize model on route change
/* route configuration */
const routes: Routes = [
{
path: 'todos',
component: TodosComponent,
resolve: {
todosInitialized: TodosService
}
}
/* ... */
@tomastrajan
tomastrajan / ampe-core-module.ts
Created May 4, 2017 22:45
Angular Model Pattern - register model provider
import { NgModule } from '@angular/core';
import { MODEL_PROVIDER } from './model.service';
@NgModule({
/* ... */
providers: [MODEL_PROVIDER]
})
export class CoreModule { }