Skip to content

Allow function to be passed to Customizer settings/scopedSettings#4677

Merged
Markionium merged 4 commits into
microsoft:masterfrom
Markionium:mapol/allow-settings-to-merge
Apr 26, 2018
Merged

Allow function to be passed to Customizer settings/scopedSettings#4677
Markionium merged 4 commits into
microsoft:masterfrom
Markionium:mapol/allow-settings-to-merge

Conversation

@Markionium

Copy link
Copy Markdown
Member

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ npm run change

Description of changes

Allows a function to be passed to the <Customizer />

This enables you to do the following

    <Customizer settings={ { field: 'Hello' } }>
        <Customizer settings={(settings) => ({ field: settings.field + 'World' })}>
          <Bar />
        </Customizer >
    </Customizer >

Bar would receive field="HelloWorld".

Focus areas to test

(optional)

return mergeSettingsWith(oldSettings);
}

function isSettingsFunction(settings?: Settings | SettingsFunction): settings is SettingsFunction {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Comment thread packages/utilities/src/Customizer.tsx Outdated
export type Settings = { [key: string]: any };
export type SettingsFunction = (settings: Settings) => Settings;

export type ICustomizerProps = Partial<{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ICustomizations is now unused? Should you delete it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not really unused as the type is still used for the CustomizerContext and GlobalSettings.getValue. But we could indeed do a bit of cleanup, so i made some minor changes.

export type SettingsFunction = (settings: Settings) => Settings;

export type ICustomizerProps = Partial<{
settings: Settings | SettingsFunction;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please add jsdoc to these?

@Markionium

Copy link
Copy Markdown
Member Author

@cliffkoh Please have a look again, i'd like to get this in around the same time as #4635 so it's easier to work with :)

@Markionium Markionium merged commit 84b34b9 into microsoft:master Apr 26, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Apr 27, 2018
* master:
  Added className to Calendar component (microsoft#4680)
  Fix bug for OWA+Safari+popup (microsoft#4681)
  Add optional props for custom divider rendering (microsoft#4687)
  Update package.json
  Add isEqual and isNotEqual utility (microsoft#4603)
  Fix minor typos (microsoft#4683)
  Allow function to be passed to Customizer settings/scopedSettings (microsoft#4677)
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Apr 27, 2018
* master:
  Added className to Calendar component (microsoft#4680)
  Fix bug for OWA+Safari+popup (microsoft#4681)
  Add optional props for custom divider rendering (microsoft#4687)
  Update package.json
  Add isEqual and isNotEqual utility (microsoft#4603)
  Fix minor typos (microsoft#4683)
  Allow function to be passed to Customizer settings/scopedSettings (microsoft#4677)
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants