0.7.38 • Published 5 years ago

@rxdi/starter-client-router-preact v0.7.38

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

@rxdi/starter-client-rxdi-router-preact

Starter project with PReact based on @rxdi/core

Powerful Dependency Injection inside Browser and Node using Typescript and RXJS 6


The idea behind @rxdi is to create independent, dependency injection that can be used everywhere, Node and Browser with purpose also to share the same code without chainging nothing! First steps where with platform called @gapi you can check repository @gapi/core. Then because of the needs of the platform i decided to develop this Reactive Dependency Injection container helping me build progressive applications. Hope you like my journey! Any help and suggestions are appreciated! Main repository @rxdi/core


Installation and basic examples:

To start developing, run:
git clone https://github.com/rxdi/starter-client-rxdi-router-preact
Install modules:
npm install
Running App

For starting and building application we will use Parcel a new configuration-less web bundler ParcelJS

This project is with added ReactJS and when builded for production bundle is less than 800Kb!!

To install parcel type:

npm install -g parcel-bundler
Start App
parcel ./src/index.html --target browser
Build App
parcel build ./src/index.html --target browser

Simplest app

Main starting point

src/main.ts

import { Bootstrap } from '@rxdi/core';
import { AppModule } from './app/app.module';

Bootstrap(AppModule, {
    init: false,
    initOptions: {
        services: true,
    },
    logger: {
        logging: true,
        date: true,
        hashes: true,
        exitHandler: true,
        fileService: true
    }
})
.subscribe(
    () => console.log('Started!'),
    (e) => console.error(e)
);

App Module

src/app/app.module.ts

import { Module } from "@rxdi/core";
import { AppComponent } from "./app.component";

@Module({
    bootstrap: [AppComponent]
})
export class AppModule {}

App Component

src/app/app.component.tsx

import { Component } from "@rxdi/core";
import { h, render, Component as PreactComponent } from 'preact';
import AsyncRoute from 'preact-async-route';
import { Router, Link } from 'preact-router';

@Component()
export class AppComponent extends PreactComponent {

    OnBefore() {
        render(<AppComponent />, document.body);
    }

    render() {
        return <div>
            <nav>
                <Link activeClassName="active" href="/">Home</Link>
                <Link activeClassName="active" href="/about">About</Link>
            </nav>
            <Router>
                <AsyncRoute
                    path="/"
                    getComponent={this.getHomeComponent}
                    loading={() => <div>loading...</div>}
                />
                <AsyncRoute
                    path="/about"
                    getComponent={this.getAboutComponent}
                    loading={() => <div>loading...</div>}
                />
            </Router>
        </div>
    }

    async getAboutComponent() {
        return (await import('./about/about.component')).AboutComponent;
    }
    async getHomeComponent() {
        return (await import('./home/home.component')).HomeComponent;
    }

}

About

import { Component } from "@rxdi/core";
import { h, Component as PreactComponent } from 'preact';

@Component()
export class AboutComponent extends PreactComponent<any> {

    render() {
        return <div>
            <h1>About </h1>
            <h1>Yey</h1>
        </div>;
    }
}

Home

import { Component } from "@rxdi/core";
import { h, Component as PreactComponent } from 'preact';

@Component()
export class HomeComponent extends PreactComponent {
    render() {
        return <div>
            <h1>Lazy routed module </h1>
            <h1>Route: </h1>
        </div>;
    }
}

Notes

@Injector() - Decorator also can be used which will depend imediately instance of Class can be used as follow

@Component()
export class AppComponent extends PreactComponent<any, any> {
    @Injector(AppService) private appService: AppService;
}

InjectSoft - Function is added due to problem when extending React.Component or Preact Component class.

Dependencies are not resolved and extended correctly by React.Component class.This is temporary solution for injecting Services when constructor is intialized and setting properties to correct constructor.

Except @Component() when extending React.Component all other decorators work as expected depending inside constructor.

When using NodeJS reamains unchanged

Later releases will be created separated class extending react and will be inside othe repository @rxdi/reactive-components Can be extended as follow

import { Component } from "@rxdi/core";
import { ReactComponent } from "@rxdi/reactive-components";
import { ReactiveService } from "../components/react.service";

@Component()
export class AppComponent extends ReactComponent<any, any> {

    // private reactiveService: ReactiveService = InjectSoft(ReactiveService); older version

    constructor(
        private reactiveService: ReactiveService
    ) {
        super();
    }

}
0.7.38

5 years ago

0.7.37

5 years ago

0.7.36

5 years ago

0.7.35

5 years ago

0.7.34

5 years ago

0.7.33

5 years ago

0.7.32

5 years ago

0.7.31

5 years ago

0.7.30

5 years ago

0.7.29

5 years ago

0.7.28

5 years ago

0.7.27

5 years ago

0.7.26

5 years ago

0.7.25

5 years ago

0.7.24

5 years ago

0.7.23

5 years ago

0.7.22

5 years ago

0.7.21

5 years ago

0.7.20

5 years ago

0.7.19

5 years ago

0.7.18

5 years ago

0.7.17

5 years ago

0.7.16

5 years ago

0.7.15

5 years ago

0.7.14

5 years ago

0.7.13

5 years ago

0.7.12

5 years ago

0.7.11

5 years ago

0.7.10

5 years ago

0.7.9

5 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.6

5 years ago

0.7.5

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.13

5 years ago

0.6.12

5 years ago

0.6.11

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.21

5 years ago

0.5.20

5 years ago

0.5.19

5 years ago

0.5.18

5 years ago

0.5.17

5 years ago

0.5.16

5 years ago

0.5.15

5 years ago

0.5.14

5 years ago

0.5.13

5 years ago

0.5.12

5 years ago

0.5.11

5 years ago

0.5.10

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.35

5 years ago

0.4.34

5 years ago

0.4.33

5 years ago

0.4.32

5 years ago

0.4.31

5 years ago

0.4.30

5 years ago

0.4.29

5 years ago

0.4.28

5 years ago

0.4.27

5 years ago

0.4.26

5 years ago

0.4.25

5 years ago

0.4.24

5 years ago

0.4.23

5 years ago

0.4.22

5 years ago

0.4.21

5 years ago

0.4.20

5 years ago

0.4.19

5 years ago

0.4.18

5 years ago

0.4.17

5 years ago

0.4.16

5 years ago

0.4.15

5 years ago

0.4.14

5 years ago

0.4.13

5 years ago

0.4.12

5 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.19

5 years ago

0.3.18

5 years ago

0.3.17

5 years ago

0.3.16

5 years ago

0.3.15

5 years ago

0.3.14

5 years ago

0.3.13

5 years ago

0.3.12

5 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.36

5 years ago

0.2.35

5 years ago

0.2.34

5 years ago

0.2.33

5 years ago

0.2.32

5 years ago

0.2.31

5 years ago

0.2.30

5 years ago

0.2.29

5 years ago

0.2.28

5 years ago

0.2.27

5 years ago

0.2.26

5 years ago

0.2.25

5 years ago

0.2.24

5 years ago

0.2.23

5 years ago

0.2.22

5 years ago

0.2.21

5 years ago

0.2.20

5 years ago

0.2.19

5 years ago

0.2.18

5 years ago

0.2.17

5 years ago

0.2.16

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.422

5 years ago

0.0.420

5 years ago

0.0.418

5 years ago

0.0.416

5 years ago

0.0.414

5 years ago

0.0.412

5 years ago

0.0.410

5 years ago

0.0.408

5 years ago

0.0.406

5 years ago

0.0.404

5 years ago

0.0.402

5 years ago

0.0.400

5 years ago

0.0.398

5 years ago

0.0.396

5 years ago

0.0.394

5 years ago

0.0.392

5 years ago

0.0.390

5 years ago

0.0.388

5 years ago

0.0.387

5 years ago

0.0.386

5 years ago

0.0.385

5 years ago

0.0.384

5 years ago

0.0.383

5 years ago

0.0.382

5 years ago

0.0.381

5 years ago

0.0.380

5 years ago

0.0.379

5 years ago

0.0.378

5 years ago

0.0.377

5 years ago

0.0.376

5 years ago

0.0.375

5 years ago

0.0.374

5 years ago

0.0.373

5 years ago

0.0.372

5 years ago

0.0.371

5 years ago

0.0.370

5 years ago

0.0.369

5 years ago

0.0.368

5 years ago

0.0.367

5 years ago

0.0.366

5 years ago

0.0.361

5 years ago

0.0.360

5 years ago

0.0.359

5 years ago

0.0.358

5 years ago

0.0.357

5 years ago

0.0.356

5 years ago

0.0.355

5 years ago

0.0.354

5 years ago

0.0.353

5 years ago

0.0.352

5 years ago

0.0.351

5 years ago

0.0.350

5 years ago

0.0.349

5 years ago

0.0.348

5 years ago

0.0.347

5 years ago

0.0.346

5 years ago

0.0.345

5 years ago

0.0.344

5 years ago