Skip to content

Commit

Permalink
🐛 Fix inheritance between components
Browse files Browse the repository at this point in the history
  • Loading branch information
GMartigny committed Apr 22, 2020
1 parent aec372a commit e314502
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const { promise: clean } = require("delete");

const component = (classe, props) => `import PComponent from "../Component";
export default ({ ${classe} }) => ({
export default (Pencil) => ({
name: "P${classe}",
extends: PComponent,
extends: PComponent(Pencil),
props: ${JSON.stringify(props)},
beforeMount () {
this.$pencil = new ${classe}(${["position", ...props, "options"].map(p => `this.${p}`).join(", ")});
this.$pencil = new Pencil.${classe}(${["position", ...props, "options"].map(p => `this.${p}`).join(", ")});
},
});
`;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PContainer from "./Container";

export default () => ({
export default (Pencil) => ({
name: "PComponent",
extends: PContainer,
extends: PContainer(Pencil),
props: ["draggable"],
mounted () {
if (!this.$pencil) {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const methods = mirroredFunctions.reduce((obj, prop) => {
return obj;
}, {});

export default ({ Scene }) => ({
export default (Pencil) => ({
name: "PScene",
extends: PContainer,
extends: PContainer(Pencil),
template: "<div><slot/></div>",
watch: {
options () {
Expand All @@ -30,12 +30,12 @@ export default ({ Scene }) => ({
beforeMount () {
// Temporary scene to host children
const container = document.createElement("div");
this.$pencil = new Scene(container, this.options);
this.$pencil = new Pencil.Scene(container, this.options);
},
mounted () {
const oldScene = this.$pencil;
const container = this.$el.parentNode;
this.$pencil = new Scene(container, this.options);
this.$pencil = new Pencil.Scene(container, this.options);
container.replaceChild(this.$pencil.ctx.canvas, this.$el);

// Transfer children from old to new scene
Expand Down

0 comments on commit e314502

Please sign in to comment.