{"size": 1241, "ext": "js", "max_stars_repo_path": "rules/layer-merge.js", "max_stars_repo_name": "bbecquet/mapbox-gl-style-optimizer", "max_stars_repo_stars_event_min_datetime": "2020-02-07T09:55:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T16:21:35.000Z", "max_issues_repo_path": "rules/layer-merge.js", "max_issues_repo_name": "bbecquet/mapbox-gl-style-optimizer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "rules/layer-merge.js", "max_forks_repo_name": "bbecquet/mapbox-gl-style-optimizer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.9814814815, "max_line_length": 79, "alphanum_fraction": 0.5656728445}
/**
 * Suggests 
 */
import * as R from 'ramda';

// these 'paint' properties cannot be controlled by data-driven expressions
// so will prevent merging too separate layers
const paintNotDataDrivenProperties = [
    'background-pattern',
    'heatmap-color',
    'line-dasharray',
    'line-gradient',
];

const keyGenerators = [
    R.prop('type'),
    R.prop('source'),
    R.prop('source-layer'),
    R.prop('minzoom'),
    R.prop('maxzoom'),
    R.prop('layout'),
    R.pipe(
        R.prop('paint'),
        R.toPairs,
        R.sortBy(R.head),
        R.filter(([ prop, value ]) => {
            return R.includes(prop, paintNotDataDrivenProperties)
                || !!value.stops
        }),
    )
];

function mergeCriterion(layer) {
    return R.pipe(
        R.map(key => key(layer)),
        R.map(R.toString),
        R.join('$')
    )(keyGenerators);
}

function allLayers(layers) {
    return R.pipe(
        R.groupBy(mergeCriterion),
        R.values,
        R.filter(layerGroup => layerGroup.length > 1),
        R.map(mergeableLayers => ({
            layerId: mergeableLayers[0].id,
            msg: `${R.pluck('id', mergeableLayers).join(' - ')} may be merged`,
        }))
    )(layers);
}

export default allLayers;
