Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@zeit/title_v3.4.x] Add definitions #3098

Merged
merged 1 commit into from Jan 26, 2019

Conversation

pascalduez
Copy link
Member

Copy link
Member

@villesau villesau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No any blockers, just suggestions. Would perhaps be good to encourage some "best practices" regarding immutability, exactness etc.

@pascalduez
Copy link
Member Author

Would perhaps be good to encourage some "best practices" regarding immutability, exactness etc.

I'm all for this.

Just wondering in this particular case whether it's that useful. Let's say one wants to reuse and mutate on options object.

let options = { specials: [''] };

title('', options);

options.specials.push(''); // Error

title('', options);

So we enforce immutability here, which is a good thing I guess.

let options = { specials: [''] };

title('', options);

let newOptions = { specials: [...options.specials, ''] };

title('', newOptions);

@villesau
Copy link
Member

villesau commented Jan 26, 2019

It actually will not error, see: https://flow.org/try/#0PTAEAEDMBsHsHcBQiAmBTAxtAhgJzaJAK4B2GALgJawmjloDO5AFJSQA5HkBcoAJACU02FAHkS0AJ4BBXLmySAPCSIBbAEZpcAPgCUvAG6xKKANzIMNJqDy5QAXlABtALrnbAOk4MAFswCMAEwAzLrm9EzMtmFAA

Taking in immutable types ensures that the value is not mutated inside the function. If you take in mutable types, you can't pass immutable values to it: https://flow.org/try/#0PTAEAEDMBsHsHcBQiAmBTAxtAhgJzaJAK4B2GALgJawmjloDO5AFJSQA5HkBcoAgrlzYAngB4SRALYAjNLgB8ASl4A3WJRQBuZBhpNCtALyhmeXLwAkAJTTYUAeRLRhAoWIky5S0IfmgA3ogAkPRMpoKK2gC+iEA

So the benefit of defining immutable types is that the function can take in immutable types (as well as mutable types, it just guarantees that they are not mutated).

Added mention of immutability and exactness: #3100

@pascalduez
Copy link
Member Author

pascalduez commented Jan 26, 2019

@villesau villesau merged commit 44ff5c6 into flow-typed:master Jan 26, 2019
@pascalduez pascalduez deleted the feature/zeit-title branch February 9, 2019 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants