Comments (5)
I'm definitely not eager to introduce lodash given that we just got rid of it.
I guess a prop that takes a custom mapping function would be possible but if there's no other use cases it seems more like it should be up to seamless-immutable to fix rather than us (they have a bug for it here). Could you use the asMutable()
method described there?
from jsx-control-statements.
It's more complicated to accomplish what you want than you imagine. Since jsx-control-statements
is a babel plugin it just transforms <For>
into map
functions, so there is no code which can be swapped out by lodash`s map implementation. The relevant code is here.
I'm afraid that both approaches are not viable:
- Instead of transforming to
myArray.map(...)
we transform to_lodash(myArray, ...)
(for example). But thenlodash
would become a peer dependency. This is quite unacceptable as @AlexGilleran pointed out. Also the implementation would be quite complicated, you would need to generate an import / require statement for every file where control statements occur, which is not as easy as it might sound. - A custom mapping function sounds like a cool feature, but the only implementation I could imagine would work on the data model you put in (right now you put in an
array
and callmap
on it:myArray.map(...)
). So it wouldn't work with lodash (_.map(immutableArray, ...)
)
I completely agree with @AlexGilleran: Use the asMutable()
workaround for this bug.
from jsx-control-statements.
Thank you for your responses. I certainly understand not wanting to pull lodash back in...especially if you just removed it. I had seen it in the codebase when looking through it previously so thought it would be an option.
As for the "bug" in seamless-immutable, the author has weighed in on it and offered some good reasons for not doing it. The use case I am trying to solve is also not unique to seamless-immutable
as the very popular ImmutableJS
lib also would not work with native map.
As for asMutable()
, unfortunately foo.asMutable() !== foo.asMutable()
which would break certain key assumptions that my app operates under.
I didn't fully follow @texttechne 2nd point. I'll dig into the code to try and understand what you are saying. I have verified that a for
loop would work with seamless-immutable
if that is an option.
from jsx-control-statements.
Just tested it with Immutable.js
and it works, since they provide a map
function for collections.
Actually this is the point I'm talking about in 2). jsx-control-statements
just calls map
on the "array" / "collection" you provide. So jsx-control-statements
does not by itself provide a specific implementation for map, it just expects that this function can be called on the given collection (it's like an interface or contract). Lodash uses a different interface, so just providing a mapping function via props won't suffice.
Unfortunately a for
loop won't work either, since it doesn't make any sense in react:
<span>
{
for(var i = 0; i < testArray.length; i++ {
var item = testArray[i];
... // what to do now? you would need to return item...
}
}
</span>
Map
functions do return something and are pure, for
loops are only meant to achieve side-effects (to speak in FP) in their body.
By the way, we can always reopen the issue if you find an approach.
from jsx-control-statements.
@lifehackett where are you using foo.asMutable() !== foo.asMutable()
in this case? As I see it you're only creating a throwaway mutable view for foo
in order to iterate over it - foo.asMutable()[0]
should still === foo[0]
.
from jsx-control-statements.
Related Issues (20)
- The control statements don't narrow TypeScript types HOT 1
- TypeScript type for children is missing a render function HOT 1
- TChildren conflicts with ReactNode children HOT 2
- Why do we need ```transform-react-inline-elements``` plugin ?
- Switch-case style control statement HOT 2
- Problem with ./node_modules/tsx-control-statements/components.ts HOT 3
- Typo error HOT 1
- Support babel macros HOT 2
- conditional statements don't work unless wrapped in brackets. is this supposed to happen? HOT 1
- Not working with laravel-mix with webpack config
- Can you provide plugins for swc HOT 1
- Can you provide a version based on swc core? HOT 1
- Uncaught ReferenceError: For is not defined HOT 5
- Not working with create-react-app HOT 7
- If is not defined HOT 4
- App breaks if i try to directly access the url - With Error - Choose is not defined HOT 1
- React-Native:Installation-Guide HOT 2
- last published version is 3 years old HOT 2
- ESLint autofix HOT 2
- Undefined is not a function with new JSX transform with react 17 HOT 3
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 jsx-control-statements.