Skip to content

Commit

Permalink
Allow script evaluation with added components
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Jun 29, 2020
1 parent 0ecb6f5 commit f792308
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 155 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
}
2 changes: 1 addition & 1 deletion dist/livewire.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/livewire.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"/livewire.js":"/livewire.js?id=b18d1e6ce7a0f48faa6c"}
{"/livewire.js":"/livewire.js?id=ab9516a37c5721cc5580"}
53 changes: 25 additions & 28 deletions js/Store.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import EventAction from "@/action/event";
import HookManager from "@/HookManager";
import DirectiveManager from "@/DirectiveManager";
import MessageBus from "./MessageBus";
import EventAction from '@/action/event'
import HookManager from '@/HookManager'
import DirectiveManager from '@/DirectiveManager'
import MessageBus from './MessageBus'

const store = {
componentsById: {},
listeners: new MessageBus,
listeners: new MessageBus(),
initialRenderIsFinished: false,
livewireIsInBackground: false,
livewireIsOffline: false,
hooks: HookManager,
Expand All @@ -19,22 +20,21 @@ const store = {
},

addComponent(component) {
return this.componentsById[component.id] = component
return (this.componentsById[component.id] = component)
},

findComponent(id) {
return this.componentsById[id]
},

getComponentsByName(name) {
return this.components()
.filter(component => {
return component.name === name
})
return this.components().filter(component => {
return component.name === name
})
},

hasComponent(id) {
return !! this.componentsById[id]
return !!this.componentsById[id]
},

tearDownComponents() {
Expand All @@ -50,28 +50,25 @@ const store = {
emit(event, ...params) {
this.listeners.call(event, ...params)

this.componentsListeningForEvent(event).forEach(
component => component.addAction(new EventAction(
event, params
))
this.componentsListeningForEvent(event).forEach(component =>
component.addAction(new EventAction(event, params))
)
},

emitUp(el, event, ...params) {
this.componentsListeningForEventThatAreTreeAncestors(el, event).forEach(
component => component.addAction(new EventAction(
event, params
))
this.componentsListeningForEventThatAreTreeAncestors(
el,
event
).forEach(component =>
component.addAction(new EventAction(event, params))
)
},

emitSelf(componentId, event, ...params) {
let component = this.findComponent(componentId)

if (component.events.includes(event)) {
component.addAction(new EventAction(
event, params
))
component.addAction(new EventAction(event, params))
}
},

Expand All @@ -80,9 +77,7 @@ const store = {

components.forEach(component => {
if (component.events.includes(event)) {
component.addAction(new EventAction(
event, params
))
component.addAction(new EventAction(event, params))
}
})
},
Expand All @@ -99,8 +94,10 @@ const store = {
}

return this.components().filter(component => {
return component.events.includes(event)
&& parentIds.includes(component.id)
return (
component.events.includes(event) &&
parentIds.includes(component.id)
)
})
},

Expand Down Expand Up @@ -131,7 +128,7 @@ const store = {

onError(callback) {
this.onErrorCallback = callback
}
},
}

export default store
Loading

0 comments on commit f792308

Please sign in to comment.