Comments (11)
I think you wanted Thumb
to be an element, not a function. In other words, the line
const Thumb = () => div(
should be
const Thumb = div(
from van.
Thanks, that worked for intersection Observer. In this case, I want the GalleryThumbs to react when their canvas.id === selectedCanvasID, but not sure how to go about it. Are these still reactive?
let selectedCanvasID = vanX.reactive('123')
const GalleryThumbs = () => {
prnt('selected id', selectedCanvasID)
return vanX.list(() => div({ id: 'galleryGrid' }), canvases, ({ val: canvas }) =>
GalleryThumb(canvas)
)
}
const GalleryThumb = (canvas) => {
const selected = selectedCanvasID === canvas.id
prnt('GALLERY', selected)
const Thumb = div(
{
id: `galleryThumb${canvas.id}`,
class: `galleryThumb ${selectedCanvasID === canvas.id ? 'selected' : ''}`,
onclick: (e) => {
if (selectedCanvasID === canvas.id) { goPaint(); loadFromID(canvas.id); return }
selectedCanvasID = canvas.id
prnt('selected canvas id', canvas.id, e.target)
},
},
div({
class: 'image',
loading: 'lazy',
}),
div({ class: `hoverable deleteButton ${selectedCanvasID === canvas.id ? '' : 'hidden'}` }),
div({ class: 'hoverable playButton hidden' }),
div({ class: 'hoverable restoreButton hidden' })
)
const galleryObserver = createGalleryObserver(canvas)
galleryObserver.observe(Thumb)
return Thumb
}
from van.
GalleryThumbs
will be reactive because of vanX.list
. But selectedCanvasID
as a reactive primitive doesn't make much sense. You can simply use van.state
for it. vanX.reactive
is for objects or arrays as a collection of reactive fields.
from van.
Thanks,
I've tried switching to van.state, but the gallery thumbs are not rerendering when selectedCanvasID is changed.
This fires when they are first generated, but never again.
prnt('gallery thumb rendered', canvas.id, selectedCanvasID)
This fires when gallery thumb is clicked, but does not cause rerender (which I want)
prnt('selected canvas id', canvas.id, e.target)
is there a way to force rerender thumbs when selectedCanvasID is changed? (only 1 should be selected at a time)
let selectedCanvasID = van.state('123')
const GalleryThumbs = () => {
prnt('gallery thumbs', selectedCanvasID)
return vanX.list(() => div({ id: 'galleryGrid' }), canvases, ({ val: canvas }) =>
GalleryThumb(canvas)
)
}
const GalleryThumb = (canvas) => {
prnt('gallery thumb rendered', canvas.id, selectedCanvasID)
const Thumb = div(
{
id: `galleryThumb${canvas.id}`,
class: `galleryThumb ${selectedCanvasID === canvas.id ? 'selected' : ''}`,
onclick: (e) => {
if (selectedCanvasID === canvas.id) { goPaint(); loadFromID(canvas.id); return }
selectedCanvasID = canvas.id
prnt('selected canvas id', canvas.id, e.target)
},
},
div({
class: 'image',
loading: 'lazy',
}),
div({ class: `hoverable deleteButton ${selectedCanvasID === canvas.id ? '' : 'hidden'}` }),
div({ class: `hoverable playButton ${selectedCanvasID === canvas.id ? '' : 'hidden'}` }),
div({ class: `hoverable restoreButton ${selectedCanvasID === canvas.id ? '' : 'hidden'}` }),
)
const galleryObserver = createGalleryObserver(canvas)
galleryObserver.observe(Thumb)
return Thumb
}
from van.
I think you should use selectedCanvasID.val
instead of selectedCanvasID
for all its appearances.
from van.
Thanks, .val works!
Now, when the selectedCanvasID changes, the thumbnail image flashes, is there a way to not rerender the image when selectedCanvasID is changed? (it should only be handled by galleryObserver and not affected by state)
let selectedCanvasID = van.state('123')
const GalleryThumbs = () => {
prnt('gallery thumbs', selectedCanvasID)
return vanX.list(() => div({ id: 'galleryGrid' }), canvases, ({ val: canvas }) =>
GalleryThumb(canvas)
)
}
const GalleryThumb = (canvas) => {
const Thumb = div(
{
id: `galleryThumb${canvas.id}`,
class: `galleryThumb ${selectedCanvasID.val === canvas.id ? 'selected' : ''}`,
onclick: (e) => {
if (selectedCanvasID.val === canvas.id) { goPaint(); loadFromID(canvas.id); return }
selectedCanvasID.val = canvas.id
prnt('selected canvas id', canvas.id, e.target)
},
},
div({
class: 'image',
loading: 'lazy',
}),
div({ class: `hoverable deleteButton ${selectedCanvasID.val === canvas.id ? '' : 'hidden'}` }),
div({ class: `hoverable playButton ${selectedCanvasID.val === canvas.id ? '' : 'hidden'}` }),
)
const galleryObserver = createGalleryObserver(canvas)
galleryObserver.observe(Thumb)
return Thumb
}
van.add(galleryGridContainer, GalleryThumbs())
from van.
I'm confused. Do you want Thumb
reactive to selectedCanvasID
, or not reactive to selectedCanvasID
?
from van.
I want class galleryThumb, deleteButton and playButton to be reactive to selectedCanvasID
I want class image to not be reactive to selectedCanvasID
from van.
My understanding is class image shouldn't be reactive to the selectedCanvasID
. Do you have a link to show the entire code?
from van.
Here's the intersection observer, I think this is everything related to the gallery thumb. is the observer being recreated on each change of selectedCanvasID?
const createGalleryObserver = (canvas) => {
const options = {
root: null,
rootMargin: '0px',
threshold: 0.1,
}
const callback = (entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const imageElement = entry.target.querySelector('.image')
if (imageElement) {
getLatestAsset(canvas.id, 'image').then((imageArrayBuffer) => {
const imageBlob = arrayToBlob(imageArrayBuffer, 'image/webp').then(
(blob) => {
const imageUrl = URL.createObjectURL(blob)
imageElement.style.backgroundImage = `url(${imageUrl})`
}
)
})
}
}
})
}
return new IntersectionObserver(callback, options)
}
from van.
Calling GalleryThumb
will create the intersection observer. So that's a possibility. Without the access to the full code, I am not able to tell what exactly can trigger the calling to GalleryThumb
. I'm not able to do any debugging, either.
from van.
Related Issues (20)
- Update Van JSX HOT 5
- Abnormal behavior under the input box. HOT 4
- vanX.list also looping empty values HOT 2
- Add a callback with just created element HOT 2
- Lifecycle event: mount and unmount HOT 1
- Error on when using method for Date data in VanX reactive (and possibly all class instance). HOT 4
- Download table broken HOT 2
- how to manually re-render? HOT 8
- Clear reactive array HOT 18
- Script children should not be escaped HOT 6
- Can createDocumentFragment be used directly? HOT 2
- Smallest reactive library HOT 6
- A way to make VanJS even smaller HOT 2
- iOS usecase?
- Array type for properties values HOT 2
- A new version of the TodoList in Javascript with editable input fields
- vanjs-jsx Fragment missing HOT 6
- [vanjs-jsx] Add missing ./src/jsx-runtime.js HOT 3
- [vanjs-jsx] style property no more handled HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from van.