Skip to content

Commit 10513f0

Browse files
authored
Merge pull request #22 from PieLabs/feature/work-pie-pie-player-2
work with pie player 2.0.0
2 parents 60e703a + 9fe2e38 commit 10513f0

8 files changed

Lines changed: 107 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.idea
33
.vscode
44
jsconfig.json
5-
lib
5+
/lib
66
node_modules
77
typings
88
typings.json
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import Tester from './tester';
4+
5+
export default class HelloWorld extends HTMLElement {
6+
createdCallback() {
7+
console.log('created..');
8+
}
9+
10+
attachedCallback() {
11+
console.log('attached..');
12+
this.dispatchEvent(new CustomEvent('pie.register', { bubbles: true }));
13+
}
14+
15+
set model(m) {
16+
this._model = m;
17+
this._render();
18+
}
19+
20+
set session(s) {
21+
this._session = s;
22+
this._render();
23+
}
24+
25+
_render() {
26+
if (this._model && this._session) {
27+
let el = React.createElement(Tester, { msg: this._model.value });
28+
ReactDOM.render(el, this);
29+
}
30+
}
31+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
export default class Tester extends React.Component{
4+
render(){
5+
return <div>hello world: {this.props.msg}</div>;
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<div>I am a vue component here is my <code>msg</code>:
3+
<span class="example">{{msg}}</span></div>
4+
</template>
5+
<script>
6+
export default {
7+
props: { msg : {type: String, default: 'default' }}
8+
}
9+
</script>
10+
11+
<style>
12+
.example {
13+
color: red;
14+
}
15+
</style>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Vue from 'vue';
2+
import Component from './component.vue';
3+
4+
export default class CorespringMultipleChoiceVueElement extends HTMLElement {
5+
constructor() {
6+
super();
7+
this._model = null;
8+
this._session = null;
9+
}
10+
11+
get model() {
12+
return this._model;
13+
}
14+
15+
set model(s) {
16+
this._model = s;
17+
this._rerender();
18+
}
19+
20+
get session() {
21+
return this._session;
22+
}
23+
24+
set session(s) {
25+
this._session = s;
26+
this._rerender();
27+
}
28+
29+
createdCallback() {
30+
this._rerender();
31+
}
32+
33+
attachedCallback() {
34+
console.log('attached');
35+
36+
this.dispatchEvent(new CustomEvent('pie.register', { bubbles: true }));
37+
}
38+
39+
_rerender() {
40+
console.log('_rerender...');
41+
42+
if (this._model) {
43+
new Vue({
44+
el: this,
45+
render: h => h(Component, { props: { msg: this._model.prompt } }),
46+
});
47+
}
48+
}
49+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<hello-world data-id="1"></hello-world>
1+
<hello-world pie-id="1"></hello-world>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1>This is a test of a vue component</h1>
2-
<vue-component data-id="1">
2+
<vue-component pie-id="1">
33
</vue-component>
44
<h1>This is a test of a react component</h1>
5-
<hello-world data-id="2">
5+
<hello-world pie-id="2">
66
</hello-world>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<h1>This is a test of a vue component</h1>
2-
<vue-component data-id="1"></vue-component>
2+
<vue-component pie-id="1"></vue-component>

0 commit comments

Comments
 (0)