Comments (5)
There isn't currently. I haven't tried making a custom PropTypes
immutability checker, but if it can be done concisely without bringing in React as a dependency, I'd be open to a PR to add it!
from seamless-immutable.
I have not looked that close at the code yet, so just asking here.
Is there any base object that the immutable objects inherit from? Or is the original objects sent in to the Immutable() function changed directly? If there is some base object available, it could just be used for instanceof check in PropTypes and any other case where it might be required to check if an object is immutable..
Something like
propTypes: {
myobject: React.PropTypes.instanceOf(Immutable())
}
given that the function without arguments (or something similar) return a base object
from seamless-immutable.
That could work with objects, but not with arrays; they need to be instanceof Array
in order to be backwards-compatible with normal arrays.
I'm open to adding a helper function intended to be used with React (as long as it doesn't necessitate a React depdendency!) but I don't want to add an extra step to the creation of every single object - even for people using seamless-immutable
outside React - for the sake of a React convenience, if that makes sense.
from seamless-immutable.
Totally understandable. Unfortunately I don't have the time to contribute with the PR myself at the moment, but maybe in the future.
from seamless-immutable.
I guess we want something that can be used like this:
React.createClass({
propTypes: {
array: Immutable.PropTypes.array,
object: Immutable.PropTypes.object
}});```
Then we can simply implement it this way: ```
function validate(type, props, propName, componentName) {
componentName = comopnentName || 'ANONYMOUS';
var msg = componentName + ".props." + propName + " is not ";
if (type === Array && ! (props[propName] instanceof Array)) return new Error(msg + ' an array');
if (type === Object && (! (props[propName] instanceof Object) || props[propName] instanceof Array)) return new Error(msg + 'an Object');
if (!Immutable.isImmutable(props[propName])) {
return new Error(msg + ' immutable');
}
return null;
}
Immutable.PropTypes = {
array: validate.bind(undefined, Array),
object: validate.bind(undefined, Object)
};
(If we want to support also .isRequred
then we can follow http://www.ian-thomas.net/custom-proptype-validation-with-react/ . Or/and it is possible to combine with the all(...arrayOfValidators)
validator from react-prop-types)
from seamless-immutable.
Related Issues (20)
- Make `without` support removing item from an array HOT 4
- how to use splice like array HOT 1
- Internet Explorer tests are failing HOT 4
- Issue regarding null values HOT 5
- Why are IE tests failing? HOT 3
- How to apply splice with seamless-immutable? HOT 1
- Merge does not work with class instances
- __immutable_invariants_hold is enumerable on Edge HOT 1
- Garbage collector features? HOT 1
- Performance characteristics
- Any difference with deepCopy? HOT 1
- [types] Mixin not applied to nested objects HOT 1
- flatMap not working HOT 2
- Add documentation for merge mode
- Files not being replaced on a deep merge
- Fails on IE 11 HOT 1
- TypeError: Object(...) is not a function HOT 1
- Lodash Vulnerability Problem
- Is the project still maintained? HOT 2
- immutable object causes rapid memory growth HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seamless-immutable.