Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alaska-field-select

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alaska-field-select - npm Package Compare versions

Comparing version 0.13.1 to 0.13.2

4

package.json
{
"name": "alaska-field-select",
"version": "0.13.1",
"version": "0.13.2",
"description": "Alaska select field",

@@ -15,5 +15,5 @@ "keywords": [

"dependencies": {
"alaska-field-checkbox": "^0.13.1",
"alaska-field-checkbox": "^0.13.2",
"react-select": "^1.2.1"
}
}

@@ -21,2 +21,38 @@ // @flow

function processOptions(
options?: Alaska$SelectField$option[],
optionsMap: {
[value: string]: Alaska$SelectField$option,
},
value: Alaska$SelectField$value
): Alaska$SelectField$option[] {
let valueMap = {};
if (Array.isArray(value)) {
_.forEach(value, (v) => {
valueMap[String(v)] = true;
});
} else {
valueMap[String(value)] = true;
}
let res = _.map(options || [], (opt) => {
if (typeof opt.style === 'string') {
opt = _.omit(opt, 'style');
}
let vKey = String(opt.value);
optionsMap[vKey] = opt;
if (valueMap[vKey]) {
delete valueMap[vKey];
}
return opt;
});
if (_.size(valueMap)) {
_.keys(valueMap).forEach((v) => {
if (optionsMap[v]) {
res.push(optionsMap[v]);
}
});
}
return res;
}
export default class Select extends React.Component<Props, State> {

@@ -31,11 +67,8 @@ static contextTypes = {

super(props);
let optionsMap = {};
let options = processOptions(props.options, optionsMap, props.value);
this.state = {
options: this.processOptions(props.options),
optionsMap: {},
options,
optionsMap
};
if (props.options) {
for (let o of props.options) {
this.state.optionsMap[String(o.value)] = o;
}
}
this.state.value = this.processValue(props.value);

@@ -54,19 +87,12 @@ this._cache = {};

let state = {};
if (props.options !== this.props.options) {
state.options = this.processOptions(props.options);
state.optionsMap = {};
if (props.options) {
for (let o of props.options) {
state.optionsMap[String(o.value)] = o;
}
if (props.options !== this.props.options || props.value !== this.props.value) {
state.optionsMap = this.state.optionsMap;
let options = props.options;
if (props.multi && props.loadOptions) {
options = this.state.options;
}
}
if (props.value !== undefined) {
state.options = processOptions(options, state.optionsMap, props.value);
state.value = this.processValue(props.value);
}
this.setState(state, () => {
if (state.optionsMap) {
this.setState({ value: this.processValue(props.value) });
}
});
this.setState(state);
}

@@ -78,11 +104,2 @@

processOptions(options?: Alaska$SelectField$option[]): Alaska$SelectField$option[] {
return _.map(options || [], (opt) => {
if (typeof opt.style === 'string') {
opt = _.omit(opt, 'style');
}
return opt;
});
}
processValue = (value: any) => {

@@ -139,4 +156,10 @@ let optionsMap = this.state.optionsMap;

handleSearchChange = (search: string) => {
if (this._cache[search]) {
this.setState({ options: this._cache[search] });
const { value } = this.props;
let { optionsMap } = this.state;
let cacheKey = 'c_' + (search || JSON.stringify(value));
if (this._cache[cacheKey]) {
this.setState({
options: processOptions(this._cache[cacheKey], optionsMap, value),
optionsMap
});
return;

@@ -147,9 +170,7 @@ }

if (!error && res.options) {
this._cache[search] = res.options;
let options = this._cache[search];
let optionsMap = {};
options.forEach((o) => {
optionsMap[o.value] = o;
this._cache[cacheKey] = res.options;
this.setState({
options: processOptions(this._cache[cacheKey], optionsMap, value),
optionsMap
});
this.setState({ options, optionsMap });
}

@@ -156,0 +177,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc