1.0.8 • Published 5 years ago

ellib v1.0.8

Weekly downloads
3
License
MIT
Repository
-
Last release
5 years ago

EL-Lib

EL-Lib is a library of common Angular components, directives, pipes and so on that I use in my Electron projects. I don't expect anyone else will ever use this library as-is but you may find some of its ideas and techniques useful.

Installation

Just in case ...

npm install --save ellib

Components

import { LibModule } from 'ellib';

@NgModule({
  imports: [LibModule]
})

AnimatedRouterOutletComponent

Just use in place of <router-outlet> for a slide-in effect on route transitions.

  <lib-animated-router-outlet>
  </lib-animated-router-outlet>

DrawerContainerComponent and DrawerPanelComponent

Wrap content so that drawers of related content slide out on command from the top, right, bottom and/or left. The drawers are modal. Examples might be filters, preferences, CRUD support and the like.

<lib-drawer-container>

  <my-toolbar
    (showPrefs)="prefsDrawer.open()">
  </my-toolbar>
  ...
  <lib-drawer-panel
    #prefsDrawer
    position="right">
    ...
  </lib-drawer-panel>

</lib-drawer-container>

Markdown Component

Wrap arbitrary markdown, which will be converted to HTML as the component loads.

<lib-markdown>
# Hello, World!
</lib-markdown>  

Requires marked which might be loaded via .angular-cli.json.

"scripts": [
  "../node_modules/marked/marked.min.js"
],

Directives

Pipes

Decorators

@AutoUnsubscribe

Annotates a components so that any RxJS subscriptions are automatically unsubscribed when the component is destroyed.

import { AutoUnsubscribe } from 'ellib';
import { LifecycleComponent } from 'ellib';

@Component({...})
@AutoUnsubscribe()
export class MyComponent extends LifecycleComponent {

  private mySubscription: Subscription;
  private anotherSubscription: Subscription;

  constructor(...) {
    super();
    // sadly if you have a ctor you have to remember to call super!
  }

  // if non null when the component is destroyed, both will be unsubscribed
  // automatically -- no other action needed

}

@OnChange

Greatly simplifies ngOnChanges handling for @Input() fields, and is especially useful when those fields are supplied via the async pipe and you need to know when they've changed.

import { OnChange } from 'ellib';
import { LifecycleComponent } from 'ellib';

@Component({...})
export class MyComponent extends LifecycleComponent {

  @Input() a;
  @Input() b;

  constructor(...) {
    super();
    // sadly if you have a ctor you have to remember to call super!
  }

  @OnChange('a', 'b')
  myChanges(changedA: boolean, changedB: boolean) {
    // the name of this method is arbitrary
    // if multiple fields are coded, then it is called if EITHER changes
    // a boolean is passed for each so you can tell what changed
    if (this.a && this.changedA) { ... }
  }

}

Animations

It took me ages to get these right. Maybe I'm not so smart as I think! I do know that I hate DSLs. I think they're all a fraud. They pretend to be intuitive but there's no way to discern the API without examples, so I offer mine as models to use, discard or improve on.

inOutAnimation

Animates the changing contents of a container by fading in the new and fading out the old.

import { inOutAnimation } from 'ellib';

@Component({
  animations: [inOutAnimation()],
  ...
})
<div [@inOut]="... expression that identifies contents ...">
  ...
</div>

showHideAnimation

Shows the contents of a container by expanding it height to fit; hides the contents by shrinking its height to zero.

import { showHideAnimation } from 'ellib';

@Component({
  animations: [showHideAnimation()],
  ...
})
<div [@showHide]="expertMode? 'shown' : 'hidden'">
  ...
</div>

routeAnimation

Designed to be used by the AnimatedRouterOutletComponent as described above. It slides the contents of the old route out to the right, and the new in from the left.

Utilities

API Summary

export declare function debounce(func: Function, wait?: number, immediate?: boolean): Function;
export declare function deepCopy<T>(obj: T): T;
export declare function dump(data: Uint8Array, title: string, ebcdic?: boolean, color?: string): void;
export declare function isObjectEmpty(obj: any): boolean;
export declare function nextTick(f: Function): void;
export declare function reverseMap(obj: any): any;
export declare function toHex(num: number, pad: number): string;

debounce

Very useful when you want to debounce but using Observable is impossible or inconvenient.

import { debounce } from 'ellib';

setup: Function;

this.setup = debounce((...) => {
  ...
}, 250);

dump

Produces a nice, expandable dump of large objects (like Buffers) to the console.

Dump

nextTick

A semantic recasting of setTimeout(..., 0) when used (for example) In Angular to force rendering.

import { nextTick } from 'ellib';

nextTick((...) => {
  ...
});
1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

8.0.1

5 years ago

0.1.125

5 years ago

0.1.124

5 years ago

0.1.123

5 years ago

0.1.122

5 years ago

0.1.121

5 years ago

0.1.120

5 years ago

0.1.119

5 years ago

0.1.118

5 years ago

0.1.117

5 years ago

0.1.116

5 years ago

0.1.115

6 years ago

0.1.114

6 years ago

0.1.113

6 years ago

0.1.112

6 years ago

0.1.111

6 years ago

0.1.110

6 years ago

0.1.109

6 years ago

0.1.108

6 years ago

0.1.107

6 years ago

0.1.106

6 years ago

0.1.105

6 years ago

0.1.104

6 years ago

0.1.103

6 years ago

0.1.102

6 years ago

0.1.101

6 years ago

0.1.100

6 years ago

0.1.99

6 years ago

0.1.98

6 years ago

0.1.97

6 years ago

0.1.96

6 years ago

0.1.95

6 years ago

0.1.94

6 years ago

0.1.93

6 years ago

0.1.92

6 years ago

0.1.91

6 years ago

0.1.90

6 years ago

0.1.89

6 years ago

0.1.88

6 years ago

0.1.87

6 years ago

0.1.86

6 years ago

0.1.85

6 years ago

0.1.84

6 years ago

0.1.83

6 years ago

0.1.82

6 years ago

0.1.81

6 years ago

0.1.80

6 years ago

0.1.79

6 years ago

0.1.78

6 years ago

0.1.77

6 years ago

0.1.76

6 years ago

0.1.73

6 years ago

0.1.72

6 years ago

0.1.71

6 years ago

0.1.70

6 years ago

0.1.69

6 years ago

0.1.68

6 years ago

0.1.67

6 years ago

0.1.66

6 years ago

0.1.65

6 years ago

0.1.64

6 years ago

0.1.63

6 years ago

0.1.62

6 years ago

0.1.61

6 years ago

0.1.60

6 years ago

0.1.59

6 years ago

0.1.58

6 years ago

0.1.57

6 years ago

0.1.56

6 years ago

0.1.55

6 years ago

0.1.54

6 years ago

0.1.53

6 years ago

0.1.52

6 years ago

0.1.51

6 years ago

0.1.50

6 years ago

0.1.49

6 years ago

0.1.48

6 years ago

0.1.47

6 years ago

0.1.46

6 years ago

0.1.45

6 years ago

0.1.44

6 years ago

0.1.43

6 years ago

0.1.42

6 years ago

0.1.41

6 years ago

0.1.40

6 years ago

0.1.39

6 years ago

0.1.38

6 years ago

0.1.37

6 years ago

0.1.36

6 years ago

0.1.35

6 years ago

0.1.34

6 years ago

0.1.33

6 years ago

0.1.32

6 years ago

0.1.31

6 years ago

0.1.30

6 years ago

0.1.29

6 years ago

0.1.28

6 years ago

0.1.27

6 years ago

0.1.26

6 years ago

0.1.25

6 years ago

0.1.24

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.21

6 years ago

0.1.20

6 years ago

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago