GithubHelp home page GithubHelp logo

utkarshx / ngx-component-mixins Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thatdevcompany/ngx-component-mixins

0.0 1.0 0.0 38 KB

A collection of useful mixins for easily extending angular components

License: MIT License

JavaScript 16.43% TypeScript 83.57%

ngx-component-mixins's Introduction

NGX Component Mixins

CircleCI

Overview

A collection of useful mixins for use in creating Angular Components

Resizable Mixin

This mixin will automatically trigger a resize method whenever the user's browser changes size

    class MyComponent extends ResizableMixin(BaseMixin) {
        doRezize({ w, h }) {
            console.log('My component's is now W wide and H high
        }
    }

Subscriber Mixin

This mixin provides automated unsubscription to Observables when a component is destroyed

    class MyComponent extends SubscriberMixin(BaseMixin) {
        doThing() {
            this.subscribeTo(someObservable, () => {
                // Do what you want
            })
        }
    }

It also provides a nice shorthand for taking just ONE event from an Observable and converting it into a Promise

    class MyComponent extends SubscriberMixin(BaseMixin) {
        doThing() {
            this.when(someObservable)
                .then(() => {
                    // Do what you want
                })
                .catch(() => {
                    // Handle the error
                })
        }
    }

Dynamic Mixin

This mixin adds the concept of TIME to the component

The component can be STARTED and STOPPED and whilst RUNNING it will TICK for each moment in time

    class MyComponent extends DynamicMixin(BaseMixin) {
        onClickPlay() {
            this.doStart()
        }
        
        onClickStop() {
            this.doStop()
        }
        
        doTick() {
            // Do whatever you want each tick of the clock
        }
    }

ngx-component-mixins's People

Contributors

utkarshx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.