This commit is contained in:
Tim
2024-02-08 03:28:55 -04:00
parent 360ee6635f
commit 1e426e8dd7
3 changed files with 57 additions and 37 deletions

View File

@@ -34,28 +34,6 @@ export const ShapeType = {
}
function updatePoints(shape, points) {
shape.lock++
try {
chart.getShapeById(shape.id).setPoints(points)
}
finally {
shape.lock--
}
}
function updateProps(shape, props) {
shape.lock++
try {
chart.getShapeById(shape.id).setProperties(props)
}
finally {
shape.lock--
}
}
class Shape {
constructor(type, model={}, onModel=null, onDelete=null) {
// the Shape object manages synchronizing internal data with a corresponding TradingView shape
@@ -69,6 +47,7 @@ class Shape {
if (onDelete !== null )
this.onDelete = onDelete
this.lock = 0 // used to prevent callbacks when we are the ones forcing the chart change
this.propsLock = 0
this.create()
}
@@ -142,7 +121,7 @@ class Shape {
delete() {
console.log('shape.delete', this.id)
// console.log('shape.delete', this.id)
if (this.id === null) return
this.lock++
try {
@@ -188,6 +167,23 @@ class Shape {
}
function updatePoints(shape, points) {
shape.lock++
try {
chart.getShapeById(shape.id).setPoints(points)
}
finally {
shape.lock--
}
}
function updateProps(shape, props) {
chart.getShapeById(shape.id).setProperties(props)
shape.propsLock++
}
// B is modifying A
function dirtyProps(propsA, propsB) {
if (propsB===null)
@@ -209,9 +205,8 @@ class ShapeTVCallbacks {
onCreate(shapeId, points, props) {
if( this.shape.id )
throw Error(`Created a shape ${shapeId}where one already existed ${this.shape.id}`)
throw Error(`Created a shape ${shapeId} where one already existed ${this.shape.id}`)
this.shape.id = shapeId
console.log('set shape id', this.shape)
if( this.shape.lock ) return
invokeCallback(this.shape, 'onCreate', points, props)
}
@@ -226,7 +221,10 @@ class ShapeTVCallbacks {
onProps(shapeId, props) {
this.shape.props = props
if( this.shape.lock ) return
if( this.shape.propsLock ) {
this.shape.propsLock--
return
}
this.shape.onProps(props)
this.shape.propsToModel()
this.shape.onModel(this.shape.model)