Skip to content

Commit a855fc0

Browse files
committed
update livewire
1 parent 51599c6 commit a855fc0

21 files changed

+1219
-491
lines changed
Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,42 @@
1-
import store from '@/Store'
2-
31
export default class {
4-
constructor(component, actionQueue) {
2+
constructor(component, updateQueue) {
53
this.component = component
6-
this.actionQueue = actionQueue
7-
}
8-
9-
get refs() {
10-
return this.actionQueue
11-
.map(action => {
12-
return action.ref
13-
})
14-
.filter(ref => ref)
4+
this.updateQueue = updateQueue
155
}
166

177
payload() {
18-
let payload = {
19-
id: this.component.id,
20-
data: this.component.data,
21-
name: this.component.name,
22-
checksum: this.component.checksum,
23-
children: this.component.children,
24-
actionQueue: this.actionQueue.map(action => {
25-
// This ensures only the type & payload properties only get sent over.
26-
return {
27-
type: action.type,
28-
payload: action.payload,
29-
}
30-
}),
8+
return {
9+
fingerprint: this.component.fingerprint,
10+
serverMemo: this.component.serverMemo,
11+
// This ensures only the type & payload properties only get sent over.
12+
updates: this.updateQueue.map(update => ({
13+
type: update.type,
14+
payload: update.payload,
15+
})),
3116
}
17+
}
3218

33-
if (Object.keys(this.component.errorBag).length > 0) {
34-
payload.errorBag = this.component.errorBag
35-
}
19+
storeResponse(payload) {
20+
return (this.response = payload)
21+
}
22+
23+
resolve() {
24+
let returns = this.response.effects.returns || []
25+
26+
this.updateQueue.forEach(update => {
27+
if (update.type !== 'callMethod') return
3628

37-
return payload
29+
update.resolve(
30+
returns[update.method] !== undefined
31+
? returns[update.method]
32+
: null
33+
)
34+
})
3835
}
3936

40-
storeResponse(payload) {
41-
return this.response = {
42-
id: payload.id,
43-
dom: payload.dom,
44-
checksum: payload.checksum,
45-
children: payload.children,
46-
dirtyInputs: payload.dirtyInputs,
47-
eventQueue: payload.eventQueue,
48-
dispatchQueue: payload.dispatchQueue,
49-
events: payload.events,
50-
data: payload.data,
51-
redirectTo: payload.redirectTo,
52-
errorBag: payload.errorBag || {},
53-
updatesQueryString: payload.updatesQueryString,
54-
}
37+
reject() {
38+
this.updateQueue.forEach(update => {
39+
update.reject()
40+
})
5541
}
5642
}

livewire/static/livewire/src/PrefetchMessage.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@ export default class extends Message {
66
}
77

88
get prefetchId() {
9-
return this.actionQueue[0].toId()
10-
}
11-
12-
payload() {
13-
return {
14-
fromPrefetch: this.prefetchId,
15-
...super.payload()
16-
}
17-
}
18-
19-
storeResponse(payload) {
20-
super.storeResponse(payload)
21-
22-
this.response.fromPrefetch = payload.fromPrefetch
23-
24-
return this.response
9+
return this.updateQueue[0].toId()
2510
}
2611
}

livewire/static/livewire/src/Store.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import EventAction from "@/action/event";
2-
import HookManager from "@/HookManager";
3-
import DirectiveManager from "@/DirectiveManager";
4-
import MessageBus from "./MessageBus";
1+
import EventAction from '@/action/event'
2+
import HookManager from '@/HookManager'
3+
import DirectiveManager from '@/DirectiveManager'
4+
import MessageBus from './MessageBus'
55

66
const store = {
77
componentsById: {},
8-
listeners: new MessageBus,
8+
listeners: new MessageBus(),
9+
initialRenderIsFinished: false,
910
livewireIsInBackground: false,
1011
livewireIsOffline: false,
12+
sessionHasExpired: false,
13+
requestIsOut: false,
1114
hooks: HookManager,
1215
directives: DirectiveManager,
16+
onErrorCallback: () => {},
1317

1418
components() {
1519
return Object.keys(this.componentsById).map(key => {
@@ -18,22 +22,21 @@ const store = {
1822
},
1923

2024
addComponent(component) {
21-
return this.componentsById[component.id] = component
25+
return (this.componentsById[component.id] = component)
2226
},
2327

2428
findComponent(id) {
2529
return this.componentsById[id]
2630
},
2731

2832
getComponentsByName(name) {
29-
return this.components()
30-
.filter(component => {
31-
return component.name === name
32-
})
33+
return this.components().filter(component => {
34+
return component.name === name
35+
})
3336
},
3437

3538
hasComponent(id) {
36-
return !! this.componentsById[id]
39+
return !!this.componentsById[id]
3740
},
3841

3942
tearDownComponents() {
@@ -49,39 +52,34 @@ const store = {
4952
emit(event, ...params) {
5053
this.listeners.call(event, ...params)
5154

52-
this.componentsListeningForEvent(event).forEach(
53-
component => component.addAction(new EventAction(
54-
event, params
55-
))
55+
this.componentsListeningForEvent(event).forEach(component =>
56+
component.addAction(new EventAction(event, params))
5657
)
5758
},
5859

5960
emitUp(el, event, ...params) {
60-
this.componentsListeningForEventThatAreTreeAncestors(el, event).forEach(
61-
component => component.addAction(new EventAction(
62-
event, params
63-
))
61+
this.componentsListeningForEventThatAreTreeAncestors(
62+
el,
63+
event
64+
).forEach(component =>
65+
component.addAction(new EventAction(event, params))
6466
)
6567
},
6668

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

70-
if (component.events.includes(event)) {
71-
component.addAction(new EventAction(
72-
event, params
73-
))
72+
if (component.listeners.includes(event)) {
73+
component.addAction(new EventAction(event, params))
7474
}
7575
},
7676

7777
emitTo(componentName, event, ...params) {
7878
let components = this.getComponentsByName(componentName)
7979

8080
components.forEach(component => {
81-
if (component.events.includes(event)) {
82-
component.addAction(new EventAction(
83-
event, params
84-
))
81+
if (component.listeners.includes(event)) {
82+
component.addAction(new EventAction(event, params))
8583
}
8684
})
8785
},
@@ -98,14 +96,16 @@ const store = {
9896
}
9997

10098
return this.components().filter(component => {
101-
return component.events.includes(event)
102-
&& parentIds.includes(component.id)
99+
return (
100+
component.listeners.includes(event) &&
101+
parentIds.includes(component.id)
102+
)
103103
})
104104
},
105105

106106
componentsListeningForEvent(event) {
107107
return this.components().filter(component => {
108-
return component.events.includes(event)
108+
return component.listeners.includes(event)
109109
})
110110
},
111111

@@ -126,7 +126,11 @@ const store = {
126126
component.tearDown()
127127
// Remove the component from the store.
128128
delete this.componentsById[component.id]
129-
}
129+
},
130+
131+
onError(callback) {
132+
this.onErrorCallback = callback
133+
},
130134
}
131135

132136
export default store
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Action from '.'
2+
3+
export default class extends Action {
4+
constructor(name, value, el) {
5+
super(el)
6+
7+
this.type = 'syncInput'
8+
this.name = name
9+
this.payload = {
10+
name,
11+
value,
12+
}
13+
}
14+
}

livewire/static/livewire/src/action/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
export default class {
33
constructor(el) {
44
this.el = el
5+
this.resolveCallback = () => {}
6+
this.rejectCallback = () => {}
57
}
68

79
get ref() {
@@ -11,4 +13,20 @@ export default class {
1113
toId() {
1214
return btoa(encodeURIComponent(this.el.el.outerHTML))
1315
}
16+
17+
onResolve(callback) {
18+
this.resolveCallback = callback
19+
}
20+
21+
onReject(callback) {
22+
this.rejectCallback = callback
23+
}
24+
25+
resolve(thing) {
26+
this.resolveCallback(thing)
27+
}
28+
29+
reject(thing) {
30+
this.rejectCallback(thing)
31+
}
1432
}

livewire/static/livewire/src/action/method.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default class extends Action {
55
super(el)
66

77
this.type = 'callMethod'
8+
this.method = method
89
this.payload = {
910
method,
1011
params,

livewire/static/livewire/src/action/model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default class extends Action {
55
super(el)
66

77
this.type = 'syncInput'
8+
this.name = name
89
this.payload = {
910
name,
1011
value,

0 commit comments

Comments
 (0)