bbc / peaks.js

JavaScript UI component for interacting with audio waveforms
https://waveform.prototyping.bbc.co.uk
GNU Lesser General Public License v3.0
3.16k stars 275 forks source link

segment.update() seems not working #481

Closed coleea closed 1 year ago

coleea commented 1 year ago

version that i use : 3.0.0-beta.7

hi.

I made some code that changes labelText of Segment. details are below.

peaks?.on('segments.click', function(segmentEvt) {
        segmentEvt.segment.update({                   
          labelText : "I changed labelText",
        })

I expected that labelText of Segment will be changed. but nothing happens.

in console.log, nothing shows. so I can't get any feedback. I don't know about what's wrong?

interesting thing is that update callback function that I wrote in segments array of PeaksOptions is called

const options : PeaksOptions  = {
      segments : [
        {
          startTime : 2 ,
          endTime : 5,
          update : (e) => {console.log("this is triggered. when I call  segmentEvt.segment.update");},
          labelText : "before modified",
          color : "#ff0000",
          id:"987",
          editable : true,
        }
      ]
};

What I am missing? Thank you

chrisn commented 1 year ago

In your segments array, you have an object with an update property:

update : (e) => {console.log("this is triggered. when I call  segmentEvt.segment.update");},

This replaces the library's internal Segment.update() method, which would cause the segment to be redrawn.

The segment should change the label text if you remove this update property.

coleea commented 1 year ago

thank you @chrisn for your answer.

I already did what you are suggested. in development mode, that works. but when I compile it, type error occurs.

As I know, update property is "required" in typescript options. So when I delete update function, type error occurs _제목 없음

ts2741 error 2741 : Property is missing in type. So I cannot delete update function.

Is It bug ?

Thank you again.

chrisn commented 1 year ago

I see, thank you! There was a bug in the TypeScript declarations. The update property should not be required.

chrisn commented 1 year ago

The fix is available in v3.0.0-beta.8.

coleea commented 1 year ago

@chrisn , thank you very much !

coleea commented 1 year ago

in version v3.0.0-beta.8, this bug is fixed ? I'm still experiencing the same error

chrisn commented 1 year ago

It should be fixed, yes, but the type has changed:

const segments: SegmentAddOptions[] = [
  {
    startTime: 2,
    endTime: 5,
    labelText: "hello"
  }
];
coleea commented 1 year ago

I got it. thank you @chrisn ! everybody should know this.

chrisn commented 1 year ago

Thank you, your feedback is really helpful!