question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Platform is a read only object

See original GitHub issue

Description

Seems like Platform object from react-native is a read only object, and mocking the functions like Version isn’t possible.

After doing Object.defineProperty(Platform, "Version", { writable: true }), I was able to update the object. Is this intentional?

Reproduction Steps and Sample Code

Example: Platform.Version = 24

Solution

Haven’t looked too deep into, but if it’s something that needs to change I’d like to do a PR for it

Additional Information

  • React Native version: 0.40
  • Platform: both

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hey99xxcommented, Apr 6, 2017

What about Platform.OS?

What about it? It’s not really different from Version.

mockablePlatform.mockInternal = (key, value) => mockablePlatform[key] = value;

if you really wanted it. What do you propose, a PR that freezes entire Platform object? I don’t see a standard in this code base that freezes the public APIs (for example all react-native keys are also writable), but then again I am not a contributor to this project so I’ll let FB engineers comment for it.

0reactions
hramoscommented, Jul 25, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

readonly keyword - C# Reference - Microsoft Learn
The readonly keyword is a modifier that can be used in four contexts: ... is a readonly reference type must always refer to...
Read more >
ReadOnly (Property Keyword) - InterSystems Documentation
ReadOnly - Specifies that a property is read-only, which limits the number of ways its value can be set.
Read more >
cannot assign to read-only property of object - Stack Overflow
the first approach you are mutating action.payload directly since you are not creating a copy to newItem but passing the same reference.
Read more >
Read-only object cache - Optimizely
Most APIs in Optimizely CMS return read-only instances of objects, such as IContentLoader.Get<TContentData> which return a read-only IContent instance.
Read more >
Read-Only Mode - Salesforce Help
What to Expect in Read-Only Mode · Add, edit, or delete data · Perform any actions in Salesforce that modify your Salesforce data....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found