├── .editorconfig ├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── example ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── elm.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── Buttons.elm │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ └── app.module.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json ├── index.ts ├── package-lock.json ├── package.json └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | insert_final_newline = false 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | **/*.js 3 | **/elm-stuff 4 | index.d.ts 5 | 6 | !karma.conf.js 7 | !protractor.conf.js 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .editorconfig 2 | .gitignore 3 | 4 | **/node_modules 5 | example 6 | build.sh 7 | clean.sh 8 | index.ts 9 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-present, Chris Camargo 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Chris Camargo nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ng-elm 2 | 3 | This package lets you embed [Elm](https://elm-lang.org/) programs inside of [Angular](https://angular.io/) components.
4 | Based off of: [https://github.com/evancz/react-elm-components](https://github.com/evancz/react-elm-components) 5 | 6 | ## Installation 7 | 8 | ```bash 9 | npm install ng-elm --save 10 | ``` 11 | 12 | ## Example 13 | 14 | - Elm Buttons - [Code](https://github.com/camargo/ng-elm/tree/master/example) 15 | 16 | ## Usage 17 | 18 | After compiling your Elm program into JavaScript, you can embed it in Angular.
19 | This example uses the [Elm buttons program](https://guide.elm-lang.org/architecture/buttons.html) : 20 | 21 | ```ts 22 | import { NgModule, Component, OnInit } from '@angular/core'; 23 | import { BrowserModule } from '@angular/platform-browser'; 24 | import { NgElmModule } from 'ng-elm'; 25 | import { Elm } from './buttons.js'; 26 | 27 | @Component({ 28 | selector: 'my-app', 29 | template: '', 30 | }) 31 | class AppComponent implements OnInit { 32 | Buttons: any; 33 | 34 | ngOnInit() { 35 | this.Buttons = Elm.Buttons; 36 | } 37 | } 38 | 39 | @NgModule({ 40 | bootstrap: [AppComponent], 41 | declarations: [AppComponent], 42 | imports: [BrowserModule, NgElmModule], 43 | }) 44 | export class AppModule {} 45 | ``` 46 | 47 | Note that flags (data passed into your Elm program from Angular), and [ports](https://guide.elm-lang.org/interop/ports.html) are also implemented. 48 | -------------------------------------------------------------------------------- /example/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events.json 15 | speed-measure-plugin.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # ng-elm Example 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.0.3. 4 | 5 | ## Start 6 | 7 | Run `npm start` to build the [Buttons.elm](./src/app/Buttons.elm) file and start the development server. 8 | 9 | ## Development Server 10 | 11 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 12 | 13 | ## Code Scaffolding 14 | 15 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 16 | 17 | ## Build 18 | 19 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 20 | 21 | ## Running Unit Tests 22 | 23 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 24 | 25 | ## Running End-to-End Tests 26 | 27 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 28 | 29 | ## Further Help 30 | 31 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 32 | -------------------------------------------------------------------------------- /example/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "example": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/example", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": false, 22 | "assets": ["src/favicon.ico", "src/assets"], 23 | "styles": ["src/styles.css"], 24 | "scripts": [] 25 | }, 26 | "configurations": { 27 | "production": { 28 | "fileReplacements": [ 29 | { 30 | "replace": "src/environments/environment.ts", 31 | "with": "src/environments/environment.prod.ts" 32 | } 33 | ], 34 | "optimization": true, 35 | "outputHashing": "all", 36 | "sourceMap": false, 37 | "extractCss": true, 38 | "namedChunks": false, 39 | "aot": true, 40 | "extractLicenses": true, 41 | "vendorChunk": false, 42 | "buildOptimizer": true, 43 | "budgets": [ 44 | { 45 | "type": "initial", 46 | "maximumWarning": "2mb", 47 | "maximumError": "5mb" 48 | } 49 | ] 50 | } 51 | } 52 | }, 53 | "serve": { 54 | "builder": "@angular-devkit/build-angular:dev-server", 55 | "options": { 56 | "browserTarget": "example:build" 57 | }, 58 | "configurations": { 59 | "production": { 60 | "browserTarget": "example:build:production" 61 | } 62 | } 63 | }, 64 | "extract-i18n": { 65 | "builder": "@angular-devkit/build-angular:extract-i18n", 66 | "options": { 67 | "browserTarget": "example:build" 68 | } 69 | }, 70 | "test": { 71 | "builder": "@angular-devkit/build-angular:karma", 72 | "options": { 73 | "main": "src/test.ts", 74 | "polyfills": "src/polyfills.ts", 75 | "tsConfig": "tsconfig.spec.json", 76 | "karmaConfig": "karma.conf.js", 77 | "assets": ["src/favicon.ico", "src/assets"], 78 | "styles": ["src/styles.css"], 79 | "scripts": [] 80 | } 81 | }, 82 | "lint": { 83 | "builder": "@angular-devkit/build-angular:tslint", 84 | "options": { 85 | "tsConfig": [ 86 | "tsconfig.app.json", 87 | "tsconfig.spec.json", 88 | "e2e/tsconfig.json" 89 | ], 90 | "exclude": ["**/node_modules/**"] 91 | } 92 | }, 93 | "e2e": { 94 | "builder": "@angular-devkit/build-angular:protractor", 95 | "options": { 96 | "protractorConfig": "e2e/protractor.conf.js", 97 | "devServerTarget": "example:serve" 98 | }, 99 | "configurations": { 100 | "production": { 101 | "devServerTarget": "example:serve:production" 102 | } 103 | } 104 | } 105 | } 106 | } 107 | }, 108 | "defaultProject": "example" 109 | } 110 | -------------------------------------------------------------------------------- /example/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /example/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /example/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to ng-elm!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser 19 | .manage() 20 | .logs() 21 | .get(logging.Type.BROWSER); 22 | expect(logs).not.toContain( 23 | jasmine.objectContaining({ 24 | level: logging.Level.SEVERE, 25 | } as logging.Entry), 26 | ); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /example/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/elm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "application", 3 | "source-directories": ["."], 4 | "elm-version": "0.19.0", 5 | "dependencies": { 6 | "direct": { 7 | "elm/browser": "1.0.0", 8 | "elm/core": "1.0.2", 9 | "elm/html": "1.0.0" 10 | }, 11 | "indirect": { 12 | "elm/json": "1.1.3", 13 | "elm/time": "1.0.0", 14 | "elm/url": "1.0.0", 15 | "elm/virtual-dom": "1.0.2" 16 | } 17 | }, 18 | "test-dependencies": { 19 | "direct": {}, 20 | "indirect": {} 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/example'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "build": "npm run build-elm && ng build", 6 | "build-elm": "elm make src/app/Buttons.elm --output=src/app/buttons.js", 7 | "clean": "rimraf elm-stuff", 8 | "e2e": "ng e2e", 9 | "lint": "ng lint", 10 | "ng": "ng", 11 | "start": "npm run build-elm && ng serve", 12 | "test": "ng test" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/animations": "~8.0.1", 17 | "@angular/common": "~8.0.1", 18 | "@angular/compiler": "~8.0.1", 19 | "@angular/core": "~8.0.1", 20 | "@angular/forms": "~8.0.1", 21 | "@angular/platform-browser": "~8.0.1", 22 | "@angular/platform-browser-dynamic": "~8.0.1", 23 | "@angular/router": "~8.0.1", 24 | "ng-elm": "..", 25 | "rxjs": "~6.4.0", 26 | "tslib": "^1.9.0", 27 | "zone.js": "~0.9.1" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.800.0", 31 | "@angular/cli": "~8.0.3", 32 | "@angular/compiler-cli": "~8.0.1", 33 | "@angular/language-service": "~8.0.1", 34 | "@types/jasmine": "~3.3.8", 35 | "@types/jasminewd2": "~2.0.3", 36 | "@types/node": "^12.0.8", 37 | "codelyzer": "^5.0.0", 38 | "elm": "0.19.0-no-deps", 39 | "jasmine-core": "~3.4.0", 40 | "jasmine-spec-reporter": "~4.2.1", 41 | "karma": "~4.1.0", 42 | "karma-chrome-launcher": "~2.2.0", 43 | "karma-coverage-istanbul-reporter": "~2.0.1", 44 | "karma-jasmine": "~2.0.1", 45 | "karma-jasmine-html-reporter": "^1.4.0", 46 | "protractor": "~5.4.0", 47 | "rimraf": "^2.6.3", 48 | "ts-node": "~7.0.0", 49 | "tslint": "~5.15.0", 50 | "typescript": "~3.4.3" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /example/src/app/Buttons.elm: -------------------------------------------------------------------------------- 1 | port module Buttons exposing (main) 2 | 3 | import Browser 4 | import Html exposing (Html, button, div, text) 5 | import Html.Events exposing (onClick) 6 | 7 | 8 | main = 9 | Browser.sandbox { init = init, update = update, view = view } 10 | 11 | 12 | -- MODEL 13 | 14 | type alias Model = Int 15 | 16 | init : Model 17 | init = 18 | 0 19 | 20 | 21 | -- UPDATE 22 | 23 | type Msg = Increment | Decrement 24 | 25 | update : Msg -> Model -> Model 26 | update msg model = 27 | case msg of 28 | Increment -> 29 | model + 1 30 | 31 | Decrement -> 32 | model - 1 33 | 34 | 35 | -- VIEW 36 | 37 | view : Model -> Html Msg 38 | view model = 39 | div [] 40 | [ button [ onClick Decrement ] [ text "-" ] 41 | , div [] [ text (String.fromInt model) ] 42 | , button [ onClick Increment ] [ text "+" ] 43 | ] 44 | -------------------------------------------------------------------------------- /example/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/camargo/ng-elm/fe66ed4b961786a54d9a553a4dadc4808601cb23/example/src/app/app.component.css -------------------------------------------------------------------------------- /example/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Welcome to ng-elm!

3 | 4 |
5 | -------------------------------------------------------------------------------- /example/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [AppComponent], 8 | }).compileComponents(); 9 | })); 10 | 11 | it('should create the app', () => { 12 | const fixture = TestBed.createComponent(AppComponent); 13 | const app = fixture.debugElement.componentInstance; 14 | expect(app).toBeTruthy(); 15 | }); 16 | 17 | it(`should have as title 'example'`, () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.debugElement.componentInstance; 20 | expect(app.title).toEqual('example'); 21 | }); 22 | 23 | it('should render title in a h1 tag', () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | fixture.detectChanges(); 26 | const compiled = fixture.debugElement.nativeElement; 27 | expect(compiled.querySelector('h1').textContent).toContain( 28 | 'Welcome to example!', 29 | ); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /example/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Elm } from './buttons.js'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'], 8 | }) 9 | export class AppComponent implements OnInit { 10 | Buttons: any; 11 | 12 | ngOnInit() { 13 | this.Buttons = Elm.Buttons; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { AppComponent } from './app.component'; 4 | import { NgElmModule } from 'ng-elm'; 5 | 6 | @NgModule({ 7 | bootstrap: [AppComponent], 8 | declarations: [AppComponent], 9 | imports: [BrowserModule, NgElmModule], 10 | }) 11 | export class AppModule {} 12 | -------------------------------------------------------------------------------- /example/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/camargo/ng-elm/fe66ed4b961786a54d9a553a4dadc4808601cb23/example/src/assets/.gitkeep -------------------------------------------------------------------------------- /example/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /example/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /example/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/camargo/ng-elm/fe66ed4b961786a54d9a553a4dadc4808601cb23/example/src/favicon.ico -------------------------------------------------------------------------------- /example/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Example 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /example/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | import { AppModule } from './app/app.module'; 4 | import { environment } from './environments/environment'; 5 | 6 | if (environment.production) { 7 | enableProdMode(); 8 | } 9 | 10 | platformBrowserDynamic() 11 | .bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /example/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /example/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /example/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting, 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting(), 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /example/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "include": [ 8 | "src/**/*.ts" 9 | ], 10 | "exclude": [ 11 | "src/test.ts", 12 | "src/**/*.spec.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "importHelpers": true, 14 | "target": "es2015", 15 | "typeRoots": ["node_modules/@types"], 16 | "lib": ["es2018", "dom"] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /example/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warn" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [true, "attribute", "app", "camelCase"], 13 | "component-selector": [true, "element", "app", "kebab-case"], 14 | "import-blacklist": [true, "rxjs/Rx"], 15 | "interface-name": false, 16 | "max-classes-per-file": false, 17 | "max-line-length": [true, 140], 18 | "member-access": false, 19 | "member-ordering": [ 20 | true, 21 | { 22 | "order": [ 23 | "static-field", 24 | "instance-field", 25 | "static-method", 26 | "instance-method" 27 | ] 28 | } 29 | ], 30 | "no-consecutive-blank-lines": false, 31 | "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], 32 | "no-empty": false, 33 | "no-inferrable-types": [true, "ignore-params"], 34 | "no-non-null-assertion": true, 35 | "no-redundant-jsdoc": true, 36 | "no-switch-case-fall-through": true, 37 | "no-use-before-declare": true, 38 | "no-var-requires": false, 39 | "object-literal-key-quotes": [true, "as-needed"], 40 | "object-literal-sort-keys": false, 41 | "ordered-imports": false, 42 | "quotemark": [true, "single"], 43 | "trailing-comma": false, 44 | "no-conflicting-lifecycle": true, 45 | "no-host-metadata-property": true, 46 | "no-input-rename": true, 47 | "no-inputs-metadata-property": true, 48 | "no-output-native": true, 49 | "no-output-on-prefix": true, 50 | "no-output-rename": true, 51 | "no-outputs-metadata-property": true, 52 | "template-banana-in-box": true, 53 | "template-no-negated-async": true, 54 | "use-lifecycle-interface": true, 55 | "use-pipe-transform-interface": true 56 | }, 57 | "rulesDirectory": ["codelyzer"] 58 | } 59 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NgModule, 3 | Component, 4 | Input, 5 | OnInit, 6 | ElementRef, 7 | ViewChild, 8 | } from '@angular/core'; 9 | 10 | @Component({ 11 | selector: 'ng-elm', 12 | template: ` 13 |
14 | `, 15 | }) 16 | class NgElmComponent implements OnInit { 17 | @Input() src: any; 18 | @Input() flags: any; 19 | @Input() ports: any; 20 | @ViewChild('el', { static: true }) element: ElementRef; 21 | 22 | ngOnInit() { 23 | const app = this.src.init({ 24 | flags: this.flags, 25 | node: this.element.nativeElement, 26 | }); 27 | 28 | if (typeof this.ports !== 'undefined') { 29 | this.ports(app.ports); 30 | } 31 | } 32 | } 33 | 34 | @NgModule({ 35 | declarations: [NgElmComponent], 36 | exports: [NgElmComponent], 37 | }) 38 | export class NgElmModule {} 39 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-elm", 3 | "version": "1.0.7", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@angular/core": { 8 | "version": "8.0.1", 9 | "resolved": "https://registry.npmjs.org/@angular/core/-/core-8.0.1.tgz", 10 | "integrity": "sha512-lUSYDztaoqpYq169MARIjtTIRuiCAioq875HQpwqApBY3zdSWPeFqU3LohUQnWq6bSVsAup5jn6Dc+juZ4YBNQ==", 11 | "requires": { 12 | "tslib": "^1.9.0" 13 | } 14 | }, 15 | "rxjs": { 16 | "version": "6.5.2", 17 | "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.2.tgz", 18 | "integrity": "sha512-HUb7j3kvb7p7eCUHE3FqjoDsC1xfZQ4AHFWfTKSpZ+sAhhz5X1WX0ZuUqWbzB2QhSLp3DoLUG+hMdEDKqWo2Zg==", 19 | "requires": { 20 | "tslib": "^1.9.0" 21 | } 22 | }, 23 | "tslib": { 24 | "version": "1.10.0", 25 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", 26 | "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==" 27 | }, 28 | "typescript": { 29 | "version": "3.5.2", 30 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.2.tgz", 31 | "integrity": "sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==", 32 | "dev": true 33 | }, 34 | "zone.js": { 35 | "version": "0.9.1", 36 | "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.9.1.tgz", 37 | "integrity": "sha512-GkPiJL8jifSrKReKaTZ5jkhrMEgXbXYC+IPo1iquBjayRa0q86w3Dipjn8b415jpitMExe9lV8iTsv8tk3DGag==" 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-elm", 3 | "version": "2.0.0", 4 | "description": "Write Angular 2 components in Elm", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "tsc", 8 | "clean": "tsc --build --clean" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/camargo/ng-elm.git" 13 | }, 14 | "dependencies": { 15 | "@angular/core": "^8.0.1", 16 | "rxjs": "^6.5.2", 17 | "zone.js": "^0.9.1" 18 | }, 19 | "devDependencies": { 20 | "typescript": "^3.5.2" 21 | }, 22 | "keywords": [ 23 | "angular", 24 | "2", 25 | "elm", 26 | "ng-elm" 27 | ], 28 | "author": "Chris Camargo", 29 | "license": "BSD-3-Clause", 30 | "bugs": { 31 | "url": "https://github.com/camargo/ng-elm/issues" 32 | }, 33 | "homepage": "https://github.com/camargo/ng-elm#readme" 34 | } 35 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "lib": ["es2015", "dom"] 7 | }, 8 | "include": ["index.ts"], 9 | "exclude": [] 10 | } 11 | --------------------------------------------------------------------------------