question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re-render a template?

See original GitHub issue

Use-case

Using a listTemplate, I would like to make the relatedContent area dynamic, populating it with content when a listItemLockup is highlighted by the user.

Consider the following (simplified) page:

import ATV from 'atvjs';
import template from './template.hbs';

const APIURL = 'http://myapi/shows';

let Page = ATV.Page.create({
  name: 'shows',
  template: template,
  events: {
    select(e) {
      console.log(e);
    },
    highlight(e) {
      // RE-RENDER
    }
  },
  ready(options, resolve, reject) {
    ATV.Ajax
      .get(APIURL)
      .then((xhr) => {
        let response = xhr.response;
        resolve(response);
      }, (xhr) => {
        let response = xhr.response;
        reject({
          status: xhr.status,
          message: response.message
        });
      });
  }
});

export default Page;

Using the ReactJS model as an analogy, I would like to be able to do something like:

  • on select event, derive data from event object to create “related content”.
  • manipulate the ‘state’ (data) of that page that gets passed to the template.
  • re-render the template with new data.

I tried to do this by storing a reference to the resolve method passed into ready and giving that fresh data but, although I can see output in the console that this has done something with the data, the page doesn’t re-render.

I’m assuming this is possible somehow, I’m probably missing something really obvious…

EDIT:

Having played around, it seems you can do some old-fashioned DOM traversal/manipulation using the reference to doc that the afterReady method receives. Although this is a passable way of doing things, I would be interested to know if there scope for something more aligned with the way modern SPA’s are built, rather than hunting down nodes and injecting content in to them.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
spunkedycommented, Aug 13, 2017

I found some of the code. I haven’t tested this in a while however, here it is.

https://gist.github.com/spunkedy/27aa9d3db6abdcb401f75c67da8be8e3

Hope this helps. I didn’t include the server side that creates the channel that accepts a longpolling mechanism.

The server side is a web socket supporting longpolling which was good enough for what I was doing.

1reaction
spunkedycommented, Aug 11, 2017

I don’t have the code around anymore. If I get a chance later I might pop it back in here. The server side has to be able to support it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to dynamically re-render template? - Stack Overflow
Currently I am trying to create a dynamic filter for listing model objects in a template. Here is the django view:
Read more >
How do I re-render a template in meteor, after calling a ...
How do I re-render a template in meteor, after calling a method, in an event? ... I think the problem is that this...
Read more >
Forcing a template rerender when the source file changes
I'm working on migrating our production setup from Docker Compose to Nomad. For context, we currently generate our configuration with a ...
Read more >
Angular directive to re-render a template if it ... - gists · GitHub
Angular directive to re-render a template if it detects any changes of the input - rerender.directive.ts.
Read more >
Angular Component Rerender - StackBlitz
template : `. <h1>Component rerender</h1>. <button (click)="rerender()">rerender</. button>. <div>. <ng-container #outlet >. </ng-container>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found