Skip to content

Live proxy: Uncaught (in promise) TypeError: Cannot read property 'push' of undefined #6

@paradis-A

Description

@paradis-A

I was trying to live proxy using the following your example

//server/index.js
const { AceBaseServer } = require("acebase-server")
const dbname = "mydb"
const server = new AceBaseServer(dbname, {
    host: "192.168.43.50",
    port: 5757,
    authentication: {
        enabled: false,
        allowUserSignup: false,
        defaultAccessRule: "allow",
        defaultAdminPassword: "75sdDSFg37w5",
    },
})
server.on("ready", () => {
    console.log("SERVER ready")
})

but changed a bit of your example. becase i dont want to wrap to async.

//client/index.js
import { AceBaseClient } from "acebase-client"
    const db = new AceBaseClient({
        host: "192.168.43.50",
        port: 5757,
        dbname: "mydb",
        https: false,
    })
    db.ready(() => {
        console.log("Connected successfully")
    })
    let liveChat = {}
    db.ref("chats/chat1")
        .proxy({})
        .then((r) => {
            liveChat = r.value
            liveChat.title = "Live Data Proxies Rock! 🚀"
            liveChat.members = ["ewout", "john", "pete", "jack"]
            liveChat.messages.push({
                from: "ewout",
                text: "Updating a database was never this easy",
            }) //throws: Uncaught (in promise) TypeError: Cannot read property 'push' of undefined
        })
    if (liveChat?.onChange)
        liveChat.onChange(function (val, prev, remoteChange, context) {
            // Handle specific (local or remote) changes:
            if (val.title !== prev.title && remoteChange) {
                console.log(`Title was changed by someone else`)
            }
            if (prev.members.includes("ewout") && !val.members.includes("ewout")) {
                console.log(remoteChange ? `I was kicked out of this chat` : `I stepped out`)
            }
        })

    function sendMessage(text) {
        // Changes made remotely are automatically updated in our liveChat object:
        if (!liveChat.members.includes("ewout")) {
            throw new Error(`Can't send message, I'm not a member anymore!`)
        }
        liveChat.messages.push({
            from: "ewout",
            text,
        })
    }

liveChat.messages.push throws
Uncaught (in promise) TypeError: Cannot read property 'push' of undefined

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions