Coder Social home page Coder Social logo

Comments (6)

valentasm1 avatar valentasm1 commented on August 12, 2024

Very nice catch.
Maybe we could check google maps version and remove fields globaly on method?
I have just basic understanding of js, so not sure about right solution.

from blazorgooglemaps.

AndreyTretyak avatar AndreyTretyak commented on August 12, 2024

I'm also don't know a lot about js. I think excluding fileds by default might be a bit risky since in the future Google Maps Api could add fields with the same names, or some customers might actually need those fields there.

I think a better approach would be to have an option of controling serialization behaivour that would allow avoiding such cases if needed.

For example define wrapper over JSON.stringify with override option and use it in the GoogleMapsComponents/wwwroot/js/objectManager.js:

const extendepbleStringify = function (obj, replacer, space) {
    if (window.blazorGoogleMapsBeforeStringify) {
          obj = window.blazorGoogleMapsBeforeStringify(obj);
    }
    return JSON.stringify(obj, replacer, space);
};

Then customers would be able to define their funtion to exclude fields that they have problem with, like this:

const removeDepricatedFieldsFromObject = function (obj) {
    if ('place_id' in obj) {
        delete obj.utc_offset
    }
    if ('opening_hours' in obj) {
        const hours = obj.opening_hours
        delete hours.open_now
    }
}

const removeDepricatedFields = function (obj) {
    if (Array.isArray(obj)) {
        for (const element of obj) {
            removeDepricatedFields(element)
        }
    } if (typeof obj === 'object' && obj !== null) {
        removeDepricatedFieldsFromObject(obj)
    }
}

window.blazorGoogleMapsBeforeStringify = function (obj) {
   removeDepricatedFields(obj);
   return obj;
};

This would also alow flexibility to adapt to future API changes and should not degrade performance too much for people who are not interested in excluding fields since warnings do not apear in most of the scenarios.

I'm not sure how common this approach are in js or is there are a nicer way, but if that's something you thin acceptable I would be happy to contribute this change. I'm also open for any other suggestions.

from blazorgooglemaps.

AndreyTretyak avatar AndreyTretyak commented on August 12, 2024

My initial issue for google API was closed as "by design", so I've created another one with alternative suggestion https://issuetracker.google.com/issues/323230578

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 12, 2024

Sorry but i am on workation, so will take a look till 18 for sure. Especially it is not critical.

from blazorgooglemaps.

AndreyTretyak avatar AndreyTretyak commented on August 12, 2024

No problem at all. Thank you for letting me know. I hope you'll have a great workation!

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 12, 2024

Reeleased
https://github.com/rungwiroon/BlazorGoogleMaps/releases/tag/4.1.0

from blazorgooglemaps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.