Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package(default_visibility = ["//visibility:public"])

exports_files(["tsconfig.json"])

# NOTE: this will move to node_modules/BUILD in a later release
filegroup(
name = "node_modules",
Expand All @@ -25,6 +23,7 @@ filegroup(
"*.d.ts",
]] + [
"node_modules/http-server/**",
"node_modules/d3/build/*",
]),
)

Expand Down Expand Up @@ -67,3 +66,10 @@ filegroup(
"//:node_modules/zone.js/dist/jasmine-patch.js",
],
)

filegroup(
name = "vendor_scripts",
srcs = [
"//:node_modules/d3/build/d3.min.js",
],
)
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@angular/common": "5.2.2",
"@angular/core": "5.2.2",
"@angular/platform-browser": "5.2.2",
"d3": "^4.12.2",
"rxjs": "5.5.6",
"zone.js": "0.8.20"
},
Expand All @@ -18,6 +19,7 @@
"@angular/platform-browser-dynamic": "5.2.2",
"@bazel/benchmark-runner": "0.1.0",
"@bazel/ibazel": "0.3.1",
"@types/d3": "^4.12.0",
"@types/jasmine": "2.8.6",
"clang-format": "1.2.2",
"concurrently": "3.5.1",
Expand Down
15 changes: 15 additions & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package(default_visibility = ["//visibility:public"])

load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

ts_library(
name = "typings",
srcs = ["typings.d.ts"],
)

ng_module(
name = "src",
Expand All @@ -18,6 +24,13 @@ genrule(
cmd = "cp $< $@",
)

genrule(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should clean this up - can be in a later PR. the ts_devserver should have an option that allows us to serve additional rootdirs, I think this is already present but maybe not wired up?

name = "d3.js",
srcs = ["//:node_modules/d3/build/d3.min.js"],
outs = ["d3.min.js"],
cmd = "cp $< $@",
)

load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")

ts_devserver(
Expand All @@ -27,6 +40,7 @@ ts_devserver(
serving_path = "/bundle.min.js",
static_files = [
":zone.js",
":d3.js",
"index.html",
],
deps = ["//src"],
Expand All @@ -46,6 +60,7 @@ nodejs_binary(
data = [
"index.html",
":bundle",
":d3.js",
":zone.js",
],
entry_point = "http-server/bin/http-server",
Expand Down
11 changes: 9 additions & 2 deletions src/hello-world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ ng_module(
"hello-world.component.ts",
"hello-world.module.ts",
],
assets = [":hello-world-styles"],
assets = [
":hello-world-styles",
":hello-world.component.html",
],
tsconfig = "//src:tsconfig.json",
deps = [
"//src:typings",
"//src/lib",
"@rxjs",
],
Expand All @@ -36,7 +40,10 @@ ts_library(

ts_web_test(
name = "test",
bootstrap = ["//:angular_bootstrap_scripts"],
bootstrap = [
"//:angular_bootstrap_scripts",
"//:vendor_scripts",
],
deps = [
":test_lib",
"//:angular_bundles",
Expand Down
3 changes: 3 additions & 0 deletions src/hello-world/hello-world.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>Hello {{ name }}</div>
<input type="text" [value]="name" (input)="name = $event.target.value"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need an actual example app. I'll ask in the GDE channel to see if we can get something good

<div class="d3-chart-container" #chart><svg><g></g></svg></div>
8 changes: 7 additions & 1 deletion src/hello-world/hello-world.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ html {
color: $example-red;
}
}
}
}

.d3-chart-container {
overflow-x: hidden;
width: 500px;
height: 500px;
}
26 changes: 21 additions & 5 deletions src/hello-world/hello-world.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import {Component, NgModule} from '@angular/core';
import {Component, ElementRef, NgModule, ViewChild} from '@angular/core';

import {msg} from '../lib/file';

@Component({
selector: 'hello-world-app',
template: `
<div>Hello {{ name }}</div>
<input type="text" [value]="name" (input)="name = $event.target.value"/>
`,
templateUrl: 'hello-world.component.html',
styleUrls: ['./hello-world-styles.css']
})
export class HelloWorldComponent {
name: string = msg;
@ViewChild('chart') public chartContainer: ElementRef;
private chart: any;

ngAfterViewInit() {
const element = this.chartContainer.nativeElement;

this.chart = d3.select(element)
.select('svg')
.attr('width', element.offsetWidth)
.attr('height', element.offsetWidth)
.select('g')
.append('circle')
.attr('class', 'node')
.attr('cy', 10)
.attr('cx', 10)
.attr('r', 10)
.style('stroke', 'gray');
}
}
2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
-->
<script src="/zone.min.js"></script>

<script src="/d3.min.js"></script>

<!--
For development mode, this script will be bundled on-the-fly by
the devserver, based on the latest JS files built by Bazel.
Expand Down
9 changes: 9 additions & 0 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as _d3 from 'd3';

// External libraries that are included as scripts such as D3 are declared as globals
// here with their appropriate types. This typings files is compiled into
// any ts_library or ng_module that requires these types and it makes them available
// as global variables that are properly typed in typescript.
declare global {
const d3: typeof _d3;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is the opposite of what we want, long-term -- we want users to import d3 if they use it, so that taze can add the proper dependency when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alex and I both agree that we need another example with d3 imported properly. This example is the only way that works at the moment with where ts_devserver and the rollup_bundle production bundler is at right now. Getting it to work with an import will require changes to both and needs to some thought.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evmar my understanding is that some libraries are documented such that developers expect to import them, but some are only accessible via globals. I think ABC needs to demonstrate both ways? If we only document how to use ES imports then I think some libraries would be unusable?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the typings usually match how the library works, so you only need a shim thing like here when you're using the library in a way contrary to its intended use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregmagolan I'm hesitant to merge this if the intended use of d3 is to import it.
What's a library that provides a better test case for ambient imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know of one off the top of my head. I'll think about it.

}
Loading