GithubHelp home page GithubHelp logo

Comments (4)

gr2m avatar gr2m commented on July 29, 2024

Can you explain a use case where you would accidentally set one of these properties such as json? I can’t think of why one would ever try to do that in the first place?

from r2.

gioragutt avatar gioragutt commented on July 29, 2024

I forgot about this issue completely :P What I meant is, that json was just an example. There are several read-only fields that are being protected from being set (with failSet), but when such a failure happens, the log message does not indicate what did you try to set. The purposed change would now look like so:

const failSet = way => () => throw new Error('Cannot set read-only property R2.${way}') // <-- see this
const resolveResWith = way => resp => resp.clone()[way]()

/* formData isn't implemented in the shim yet */
const ways = ['json', 'text', 'arrayBuffer', 'blob', 'formData']
ways.forEach(way =>
  Object.defineProperty(this, way, {
    get: () => this.response.then(resolveResWith(way)),
    set: failSet(way) // <--  fail set will tell you what read-only property you tried to change
  })
)

from r2.

gr2m avatar gr2m commented on July 29, 2024

gotcha, thanks for following up after all this time πŸ‘ I’ll leave this open but I think it will become obsolete as we will move away from the getters and use functions instead in a future version, as discussed in #22

from r2.

gioragutt avatar gioragutt commented on July 29, 2024

@gr2m got it πŸ˜„ methods are definitely the better solution over getters+(unwanted)setters.

I'm not using the library now, I don't even remember when I had to use it, but I'm glad that good design decisions are taken nonetheless. Keep it up πŸ‘

from r2.

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.