Skip to content

Commit

Permalink
Reimplement custom element example
Browse files Browse the repository at this point in the history
Refactor custom element example to conform to the newest versions of
rxmarbles components.

Add ES5 custom web component shim, since source code for rxmarbles
clasess is compiled to ES5.

Update webpack config to compile new custom element source file into
distribution folder.

Related to staltz#48.
  • Loading branch information
xtianjohns committed Oct 11, 2017
1 parent a31e372 commit 4979838
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
24 changes: 24 additions & 0 deletions dist/element.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/element.js.map

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import run from '@cycle/rxjs-run';
import { Observable } from 'rxjs/Observable';
import { makeDOMDriver, h } from '@cycle/dom';
import { Sandbox } from './components/sandbox/sandbox';
import { merge } from 'ramda';

class SandboxElement extends HTMLElement {
connectedCallback() {
let key = this.attributes.key.value;
function main( sources ) {
const sandbox = Sandbox( sources );
const sinks = {
DOM: sandbox.DOM,
store: Observable.merge( sandbox.data ).scan(merge, { route: key, inputs: undefined }),
};
return sinks;
}

run(main, {
DOM: makeDOMDriver(this),
store: sources => sources,
});
}
}

customElements.define( 'rx-marbles', SandboxElement );
3 changes: 2 additions & 1 deletion test-custom-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<meta name="description" content="Learn, build, and test Rx functions on Observables">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RxMarbles: Interactive diagrams of Rx Observables</title>
<script src="dist/js/element.js"></script>
<script src="https://rawgit.com/webcomponents/custom-elements/master/src/native-shim.js"></script>
<script src="dist/element.js"></script>
</head>
<body>
<!--[if lt IE 7]>
Expand Down
7 changes: 5 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ if (isProduction) {
}

module.exports = {
entry: './src/app.js',
entry: {
app: './src/app.js',
element: './src/element.js'
},

output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.js',
filename: '[name].js',
},

devtool: isProduction ?
Expand Down

0 comments on commit 4979838

Please sign in to comment.