arguiot/DisplayJS

Not work $.dynamic() on first change

ange007 opened this issue · 5 comments

Not work (p show - '00'):

<p var="time"></p>

var data = { time: '00' };
var $ = new DisplayJS( data );

 $.dynamic( function( )
{
    const time = new Date();
    data.time = time.getHours();
} );

 $.var( true );

Work (p show - current time) :

<p var="time"></p>

var data = { time: '00' };
var $ = new DisplayJS( data );

 $.dynamic( function( )
{
    const time = new Date();
    data.time = time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds();
} );

 $.var( true );

Try that maybe 🤔:

<p var="time"></p>

var data = { time: 0 };
var $ = new DisplayJS( data );

 $.dynamic( function( )
{
    const time = new Date();
    data.time = time.getHours();
} );

 $.var( true );

Did it worked?? I'll close this issue, but if there is any updates, I'll reopen it 😊

No, it does not work.

Ok, don’t worry 😉 I’ll work on this problem as soon as I have access to my computer 💻 because I’m currently not at home 🏡

Ok, I found the problem and it's easy to fix. The $.live() push method is unstable and has some bugs. Here is a fix that works:

<p var="time"></p>

var data = { time: '00' };
var $ = new DisplayJS( data );
var time = new Date();
data.time = String(time.getHours());

 $.dynamic( function( )
{
    time = new Date();
    data.time = String(time.getHours());
} );

 $.var( true );

I'm trying to fix the $.live() method but as I said, it's not 100% sure, so try to update the content before and after the event/change to fix the problem 😊.