15

As a developer, I enjoy playing with different technologies and seeing what I can learn from, and what ideas I might bring back when working on SFDC (my bread and butter).

I'm currently looking at ReactJS and learning about "Pure Components" and the idea that most components should be stateless which allows for a more functional style of development and testing.

Obviously, since SFDC isn't giving us immutable collections or variables or even a way to annotate Lightning components as pure, there will be limits to how well we might leverage the idea in SFDC and what benefits we might see.

But I'm wondering if anyone has had any success (or noteworthy failures) trying to develop Lightning Components as pure components and whether you'd have any suggestions for anyone else who might want to go down that road?

  • This question seems like it might be a bit too broad for this platform. "Have you tried X?" questions have historically been a poor fit. – Adrian Larson Feb 16 '18 at 14:24
  • Probably, but if you know a better place to ask it, I'd be happy to. – Brian Kessler Feb 17 '18 at 15:07
  • 1
    Hence why I didn't close it. I'm not sure either. Just calling out this post is an exception to the rule. – Adrian Larson Feb 17 '18 at 15:24
1

The primary purpose of React's pure components is to be able to determine if it needs to rerender a component based on the values passed in. Aura does not have this level of sophistication, instead rerendering based on aura:valueChange events; in the truest sense, a pure component in Lightning would necessarily be static. That said, any component that doesn't expose a UI, like a data service component, could be written as a pure component.

On the other hand, calls to the server can work like pure functions (via setStorable). If you can ascertain that a particular call is idempotent within a reasonable amount of time, it might make sense to make your actions storable, which allows Aura to cache response values based on the parameters passed in to the action, avoiding additional round trips to the server when they aren't necessary.

Note that while the responses are cached, they are automatically updated periodically, which can result in the same callback being called more than once. You may need to account for this. You can read more about it in Storable Actions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.