Skip to content

Commit

Permalink
Merge branch 'profile'
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Jun 9, 2023
2 parents f92126a + e70b8d2 commit b175da1
Show file tree
Hide file tree
Showing 50 changed files with 1,593 additions and 1,049 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "syntheticjs/support",
"name": "livewire/livewire",
"version": "2.99.99",
"description": "A front-end framework for Laravel.",
"license": "MIT",
"authors": [
Expand Down
115 changes: 68 additions & 47 deletions dist/livewire.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,10 @@
return (result) => {
let latest = result;
for (let i = 0; i < finishers.length; i++) {
latest = finishers[i](latest);
let iResult = finishers[i](latest);
if (iResult !== void 0) {
latest = iResult;
}
}
return latest;
};
Expand Down Expand Up @@ -1485,7 +1488,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
let typeB = directiveOrder.indexOf(b.type) === -1 ? DEFAULT : b.type;
return directiveOrder.indexOf(typeA) - directiveOrder.indexOf(typeB);
}
function dispatch(el, name, detail = {}) {
function dispatch2(el, name, detail = {}) {
el.dispatchEvent(new CustomEvent(name, {
detail,
bubbles: true,
Expand Down Expand Up @@ -1526,7 +1529,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
Array.from(document.querySelectorAll(allSelectors())).filter(outNestedComponents).forEach((el) => {
initTree(el);
});
dispatch(document, "alpine:initialized");
dispatch2(document, "alpine:initialized");
}
var rootSelectorCallbacks = [];
var initSelectorCallbacks = [];
Expand Down Expand Up @@ -2991,7 +2994,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
return Boolean(r && r.__v_isRef === true);
}
magic("nextTick", () => nextTick);
magic("dispatch", (el) => dispatch.bind(dispatch, el));
magic("dispatch", (el) => dispatch2.bind(dispatch2, el));
magic("watch", (el, { evaluateLater: evaluateLater2, effect: effect3 }) => (key, callback) => {
let evaluate2 = evaluateLater2(key);
let firstTime = true;
Expand Down Expand Up @@ -3835,15 +3838,15 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
});
successReceivers.push((snapshot, effects) => {
target.mergeNewSnapshot(snapshot, effects);
processEffects(target);
processEffects(target, target.effects);
if (effects["returns"]) {
let returns = effects["returns"];
let returnHandlerStack = request.calls.map(({ handleReturn }) => handleReturn);
returnHandlerStack.forEach((handleReturn, index) => {
handleReturn(returns[index]);
});
}
finishTarget();
finishTarget({ snapshot, effects });
request.handleResponse();
});
});
Expand All @@ -3859,13 +3862,14 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
"X-Synthetic": ""
}
};
let finishWiretap = trigger2("wiretap.request", options);
let finishFetch = trigger2("fetch", uri, options);
let response = await fetch(uri, options);
response = finishFetch(response);
let succeed = async (responseContent) => {
let response2 = JSON.parse(responseContent);
for (let i = 0; i < response2.length; i++) {
let { snapshot, effects } = response2[i];
let { components: components2 } = JSON.parse(responseContent);
for (let i = 0; i < components2.length; i++) {
let { snapshot, effects } = components2[i];
successReceivers[i](snapshot, effects);
}
};
Expand All @@ -3875,19 +3879,18 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
}
let failed = true;
};
await handleResponse(response, succeed, fail);
await handleResponse(response, succeed, fail, finishWiretap);
}
function getCsrfToken() {
if (document.querySelector("[data-csrf]")) {
return document.querySelector("[data-csrf]").getAttribute("data-csrf");
}
throw "Livewire: No CSRF token detected";
}
function processEffects(target) {
let effects = target.effects;
function processEffects(target, effects) {
trigger2("effects", target, effects);
}
async function handleResponse(response, succeed, fail) {
async function handleResponse(response, succeed, fail, finishWiretap) {
let content = await response.text();
if (response.ok) {
if (response.redirected) {
Expand All @@ -3896,9 +3899,13 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
if (contentIsFromDump(content)) {
[dump, content] = splitDumpFromContent(content);
showHtmlModal(dump);
finishWiretap({ content: "{}", failed: true });
} else {
finishWiretap({ content, failed: false });
}
return await succeed(content);
}
finishWiretap({ content: "{}", failed: true });
let skipDefault = false;
trigger2("response.error", response, content, () => skipDefault = true);
if (skipDefault)
Expand Down Expand Up @@ -4054,12 +4061,12 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
return parent.$wire;
});
wireProperty("$on", (component) => (...params) => listen(component, ...params));
wireProperty("$dispatch", (component) => (...params) => dispatch2(...params));
wireProperty("$dispatchSelf", (component) => (...params) => dispatchSelf(component.id, ...params));
wireProperty("$dispatchTo", (component) => (...params) => dispatchTo(...params));
wireProperty("dispatch", (component) => (...params) => dispatch2(...params));
wireProperty("dispatchSelf", (component) => (...params) => dispatchSelf(component.id, ...params));
wireProperty("dispatchTo", (component) => (...params) => dispatchTo(...params));
wireProperty("$dispatch", (component) => (...params) => dispatch3(component, ...params));
wireProperty("$dispatchSelf", (component) => (...params) => dispatchSelf(component, ...params));
wireProperty("$dispatchTo", (component) => (...params) => dispatchTo(component, ...params));
wireProperty("dispatch", (component) => (...params) => dispatch3(component, ...params));
wireProperty("dispatchSelf", (component) => (...params) => dispatchSelf(component, ...params));
wireProperty("dispatchTo", (component) => (...params) => dispatchTo(component, ...params));

// js/component.js
var Component = class {
Expand All @@ -4080,7 +4087,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
this.ephemeral = extractData(deepClone(this.snapshot.data));
this.reactive = Alpine.reactive(this.ephemeral);
this.$wire = generateWireObject(this, this.reactive);
processEffects(this);
processEffects(this, this.effects);
}
mergeNewSnapshot(encodedSnapshot, effects) {
this.encodedSnapshot = encodedSnapshot;
Expand All @@ -4095,6 +4102,16 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
}
});
}
replayUpdate(snapshot, html, dirty) {
let effects = { ...this.effects, html, dirty };
this.mergeNewSnapshot(JSON.stringify(snapshot), effects);
processEffects(this, { html, dirty });
}
get children() {
let meta = this.snapshot.memo;
let childIds = Object.values(meta.children).map((i) => i[1]);
return childIds.map((id) => findComponent(id));
}
};

// js/store.js
Expand Down Expand Up @@ -4126,6 +4143,9 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
return name == component.name;
});
}
function getByName(name) {
return componentsByName(name).map((i) => i.$wire);
}
function find(id) {
let component = components[id];
return component && component.$wire;
Expand All @@ -4142,50 +4162,53 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
function registerListeners(component, listeners2) {
listeners2.forEach((name) => {
window.addEventListener(name, (e) => {
if (e.__livewire)
e.__livewire.receivedBy.push(component);
component.$wire.call("__dispatch", name, e.detail);
});
component.el.addEventListener(name, (e) => {
if (e.__livewire && e.bubbles)
return;
if (e.__livewire)
e.__livewire.receivedBy.push(component.id);
component.$wire.call("__dispatch", name, e.detail);
});
});
}
function dispatchEvents(component, dispatches) {
dispatches.forEach(({ name, params = {}, self: self2 = false, to }) => {
if (self2)
dispatchSelf(component.id, name, params);
dispatchSelf(component, component.id, name, params);
else if (to)
dispatchTo(to, name, params);
dispatchTo(component, to, name, params);
else
dispatch2(name, params);
dispatch3(component, name, params);
});
}
function dispatchEvent(el, name, params, bubbles = true) {
function dispatchEvent(component, target, name, params, bubbles = true) {
let e = new CustomEvent(name, { bubbles, detail: params });
e.__livewire = { name, params };
el.dispatchEvent(e);
e.__livewire = { from: component.id, name, params, receivedBy: [] };
trigger2("dispatch", e);
target.dispatchEvent(e);
}
function dispatch2(name, params) {
dispatchEvent(window, name, params);
function dispatch3(component, name, params) {
dispatchEvent(component, window, name, params);
}
function dispatchSelf(id, name, params) {
let component = findComponent(id);
dispatchEvent(component.el, name, params, false);
function dispatchSelf(component, name, params) {
dispatchEvent(component, component.el, name, params, false);
}
function dispatchTo(componentName, name, params) {
let components2 = componentsByName(componentName);
components2.forEach((component) => {
dispatchEvent(component.el, name, params, false);
function dispatchTo(component, componentName, name, params) {
let targets = componentsByName(componentName);
targets.forEach((target) => {
dispatchEvent(component, target.el, name, params, false);
});
}
function listen(component, name, callback) {
component.el.addEventListener(name, (e) => {
callback(e.detail);
});
}
function on3(name, callback) {
globalListeners.add(name, callback);
function on3() {
}

// js/directives.js
Expand Down Expand Up @@ -4844,10 +4867,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);

// js/features/supportWireModelingNestedComponents.js
on("request.prepare", (component) => {
let meta = component.snapshot.memo;
let childIds = Object.values(meta.children).map((i) => i[1]);
childIds.forEach((id) => {
let child = findComponent(id);
component.children.forEach((child) => {
let childMeta = child.snapshot.memo;
let bindings = childMeta.bindings;
if (bindings)
Expand Down Expand Up @@ -4931,10 +4951,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);

// js/features/supportReactiveProps.js
on("request.prepare", (component) => {
let meta = component.snapshot.memo;
let childIds = Object.values(meta.children).map((i) => i[1]);
childIds.forEach((id) => {
let child = findComponent(id);
component.children.forEach((child) => {
let childMeta = child.snapshot.memo;
let props = childMeta.props;
if (props)
Expand Down Expand Up @@ -5208,7 +5225,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
let to = wrapper.firstElementChild;
to.__livewire = component;
trigger("morph", el, to, component);
Alpine.morph(el, to, {
module_default.morph(el, to, {
updating: (el2, toEl, childrenOnly, skip) => {
if (isntElement(el2))
return;
Expand Down Expand Up @@ -5809,11 +5826,13 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
var Livewire = {
directive: directive2,
dispatchTo,
getByName,
start: start2,
first,
find,
hook: on,
dispatch: dispatch2,
trigger: trigger2,
dispatch: dispatch3,
on: on3
};
if (window.Livewire)
Expand All @@ -5822,5 +5841,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
console.warn("Detected multiple instances of Alpine running");
window.Livewire = Livewire;
window.Alpine = module_default;
dispatch(document, "livewire:init");
Livewire.start();
dispatch(document, "livewire:initialized");
})();
Empty file added docs/Untitled 1.md
Empty file.
2 changes: 2 additions & 0 deletions docs/Untitled 2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
39"

7 changes: 6 additions & 1 deletion docs/__nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Essentials:
Lifecycle Hooks: { uri: /docs/lifecycle-hooks, file: /lifecycle-hooks.md }
Nesting Components: { uri: /docs/nesting, file: /nesting.md }
Testing: { uri: /docs/testing, file: /testing.md }
Upgrade Guide: { uri: /docs/upgrading, file: /upgrading.md }
Features:
Navigation: { uri: /docs/navigation, file: /navigation.md }
Lazy Loading: { uri: /docs/lazy, file: /lazy.md }
Expand All @@ -25,8 +24,14 @@ Features:
Redirecting: { uri: /docs/redirecting, file: /redirecting.md }
Polling: { uri: /docs/polling, file: /polling.md }
File Downloads: { uri: /docs/downloads, file: /downloads.md }
Locked Properties: { uri: /docs/locked, file: /locked.md }
Dirty states: { uri: /docs/dirty, file: /dirty.md }
Offline states: { uri: /docs/offline, file: /offline.md }
Concepts:
Hydration: { uri: /docs/hydration, file: /hydration.md }
Nesting: { uri: /docs/understanding-nesting, file: /understanding-nesting.md }
Advanced:
Extending Livewire: { uri: /docs/extending, file: /extending.md }
---

Concepts:
Expand Down
2 changes: 1 addition & 1 deletion docs/__outline.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Should I ditch the terms "hydrate" and "dehydrate"? Hydrate is normally used for hydrating front-end behavior from a frozen state. Well, we're just applying it to the backend. Serialize and unserialize are alternatives as are "sleep" and "wakeup".
Should I ditch the terms "hydrate" and "dehydrate"? Hydrate is normally used for hydrating frontend behavior from a frozen state. Well, we're just applying it to the backend. Serialize and unserialize are alternatives as are "sleep" and "wakeup".

* more examples
* best practices
Expand Down
Loading

0 comments on commit b175da1

Please sign in to comment.