-
Notifications
You must be signed in to change notification settings - Fork 626
Optimize area apps take 3 #5280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,9 @@ export default function() { | |
| createAreaAppsAndRunPlayersIfDone(); | ||
| }); | ||
|
|
||
| function createAreaAppsAndRunPlayersIfDone({ edit = true } = {}) { | ||
| function createAreaAppsAndRunPlayersIfDone({ edit = true, el = null } = {}) { | ||
| if (edit) { | ||
| createAreaApps(); | ||
| createAreaApps(el); | ||
| nextTick(() => { | ||
| cleanupOrphanedApps(); | ||
| }); | ||
|
|
@@ -39,23 +39,14 @@ export default function() { | |
| } | ||
| } | ||
|
|
||
| function createAreaApps() { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this already landed. OK github... |
||
| // Sort the areas by DOM depth to ensure parents light up before children | ||
| const els = Array.from(document.querySelectorAll('[data-apos-area-newly-editable]')); | ||
| els.sort((a, b) => { | ||
| const da = depth(a); | ||
| const db = depth(b); | ||
| if (da < db) { | ||
| return -1; | ||
| } else if (db > da) { | ||
| return 1; | ||
| } else { | ||
| return 0; | ||
| } | ||
| }); | ||
| for (const el of els) { | ||
| createAreaApp(el); | ||
| } | ||
| function createAreaApps(el) { | ||
| // Create apps only for the areas at the top of the nesting | ||
| // hierarchy in the given context. widget-rendered events will | ||
| // cause more invocations later, avoiding double invocations, | ||
| // orphaned apps and wasted time. -Tom | ||
| const els = Array.from((el || document).querySelectorAll('[data-apos-area-newly-editable]')); | ||
| const lowest = Math.min(...els.map(el => depth(el))); | ||
| els.filter(el => depth(el) === lowest).forEach(el => createAreaApp(el)); | ||
| } | ||
|
|
||
| function depth(el) { | ||
|
|
@@ -107,6 +98,9 @@ export default function() { | |
| } | ||
| el.removeAttribute('data-apos-area-newly-editable'); | ||
|
|
||
| let created = false; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new. |
||
| let observer; | ||
|
|
||
| if (apos.area.activeEditor && (apos.area.activeEditor.id === data._id)) { | ||
| // Editing a piece causes a refresh of the main content area, | ||
| // but this may contain the area we originally intended to add | ||
|
|
@@ -116,6 +110,20 @@ export default function() { | |
|
|
||
| el.parentNode.replaceChild(apos.area.activeEditor.$el, el); | ||
| } else { | ||
| observer = new IntersectionObserver(observed, { | ||
| rootMargin: '600px' | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helps avoid any jank feeling caused by watching the area editor change the height and sometimes width of things: we do it 600px before they actually become visible. |
||
| }); | ||
| observer.observe(el); | ||
| } | ||
|
|
||
| function observed(entries) { | ||
| const intersects = entries[0].isIntersecting; | ||
| if (!intersects) { | ||
| return; | ||
| } | ||
| if (created) { | ||
| return; | ||
| } | ||
| const app = createApp(component, { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it's close to becoming visible so let's do the work. |
||
| options, | ||
| id: data._id, | ||
|
|
@@ -127,9 +135,10 @@ export default function() { | |
| parentOptions, | ||
| renderings | ||
| }); | ||
|
|
||
| app.mount(el); | ||
| mountedApps.set(el, app); | ||
| created = true; | ||
| observer.disconnect(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main should already have this from my last PR, don't know why it shows up again.