override fun init()

in rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/impl/RdProperty.kt [64:100]


    override fun init(lifetime: Lifetime, proto: IProtocol, ctx: SerializationCtx) {
        super.init(lifetime, proto, ctx)

        val value = valueOrNull
        var hasInitValue = value != null
        if (hasInitValue && !optimizeNested)
            value.bindPolymorphic()

        advise(lifetime) { v ->
            val shouldIdentify = !hasInitValue
            hasInitValue = false

            if (!isLocalChange)
                return@advise

            if (!optimizeNested && shouldIdentify) {
                // We need to terminate the current lifetime to unbind the existing value before assigning a new value, especially in cases where we are reassigning it.
                bindDefinition.get()?.terminate()

                v.identifyPolymorphic(proto.identity, proto.identity.next(rdid))

                val prevDefinition = bindDefinition.getAndSet(tryPreBindValue(lifetime, v, false))
                prevDefinition?.terminate()
            }

            if (master) masterVersion++

            proto.wire.send(rdid) { buffer ->
                buffer.writeInt(masterVersion)
                valueSerializer.write(ctx, buffer, v)
                logSend.trace { "property `$location` ($rdid):: ver = $masterVersion, value = ${v.printToString()}" }
            }

            if (!optimizeNested && shouldIdentify)
                v.bindPolymorphic()
        }
    }