Skip to content

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented May 4, 2022

Currently yield 42 resolves to undefined. Now it resolves to the yielded value, 42. In the case a promise is yielded, it resolves to the resolved promise value, similar to await. This makes it easier e.g. to create a map with Leaflet. Instead of:

viewof map = {
  const container = htl.html`<div style="height:600px;">`;
  yield container;
  const map = container.value = new mapboxgl.Map({
    container,
    center: [-77.033485, 38.897205],
    zoom: 10,
    style: "mapbox://styles/mapbox/streets-v11",
    scrollZoom: false
  });
  invalidation.then(() => map.remove());
}

You can now say:

viewof map = {
  const container = yield htl.html`<div style="height:600px;">`;
  const map = container.value = new mapboxgl.Map({
    container,
    center: [-77.033485, 38.897205],
    zoom: 10,
    style: "mapbox://styles/mapbox/streets-v11",
    scrollZoom: false
  });
  invalidation.then(() => map.remove());
}

@mbostock mbostock requested a review from visnup May 4, 2022 18:08
@visnup
Copy link
Member

visnup commented May 5, 2022

There's no possible way for the user to get the underlying generator for a cell with a yield, right? If so, that could open up a method to send information back to the yield from outside.

@mbostock
Copy link
Member Author

mbostock commented May 5, 2022

There's no possible way for the user to get the underlying generator for a cell with a yield, right?

No, not unless we introduce a new operator like generatorof, but I’m not even sure how that would work because only one thing can be responsible for running the generator. So, I think it’s unlikely we’d ever want yield to return something else.

@mbostock mbostock merged commit 5116f09 into main May 9, 2022
@mbostock mbostock deleted the mbostock/yield-value branch May 9, 2022 19:50
@Fil
Copy link
Contributor

Fil commented May 9, 2022

I got @visnup to explain that to me and … 🤯 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants