mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
added IssueManager
- IssueManager performs validation on the current graph and also stores the issues and notifies listeners when the issues changed
This commit is contained in:
@@ -13,6 +13,7 @@ import { select as d3_select } from 'd3-selection';
|
||||
import { t, currentLocale, addTranslation, setLocale } from '../util/locale';
|
||||
|
||||
import { coreHistory } from './history';
|
||||
import { IssueManager } from '../validations/issueManager';
|
||||
import { dataLocales, dataEn } from '../../data';
|
||||
import { geoRawMercator } from '../geo/raw_mercator';
|
||||
import { modeSelect } from '../modes/select';
|
||||
@@ -95,10 +96,10 @@ export function coreContext() {
|
||||
|
||||
|
||||
/* Straight accessors. Avoid using these if you can. */
|
||||
var connection, history;
|
||||
var connection, history, issueManager;
|
||||
context.connection = function() { return connection; };
|
||||
context.history = function() { return history; };
|
||||
|
||||
context.issueManager = function() { return issueManager; };
|
||||
|
||||
/* Connection */
|
||||
context.preauth = function(options) {
|
||||
@@ -446,6 +447,8 @@ export function coreContext() {
|
||||
context.changes = history.changes;
|
||||
context.intersects = history.intersects;
|
||||
|
||||
issueManager = IssueManager(context);
|
||||
|
||||
// Debounce save, since it's a synchronous localStorage write,
|
||||
// and history changes can happen frequently (e.g. when dragging).
|
||||
context.debouncedSave = _debounce(context.save, 350);
|
||||
|
||||
@@ -11,8 +11,8 @@ export function uiCommitWarnings(context) {
|
||||
|
||||
function commitWarnings(selection) {
|
||||
|
||||
var changes = context.history().changes();
|
||||
var validations = context.history().validate(changes);
|
||||
// maybe call these issues now?
|
||||
var validations = context.issueManager().validate();
|
||||
|
||||
validations = _reduce(validations, function(validations, val) {
|
||||
var severity = val.severity;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import * as d3 from 'd3';
|
||||
import { utilRebind } from '../util/rebind';
|
||||
|
||||
export function IssueManager(context) {
|
||||
var dispatch = d3.dispatch('reload'),
|
||||
self = {},
|
||||
issues = [];
|
||||
|
||||
self.getIssues = function() {
|
||||
self.validate();
|
||||
return issues;
|
||||
};
|
||||
|
||||
self.validate = function() {
|
||||
var changes = context.history().changes();
|
||||
issues = context.history().validate(changes);
|
||||
dispatch.call('reload', self, issues);
|
||||
return issues;
|
||||
};
|
||||
|
||||
return utilRebind(self, dispatch, 'on');
|
||||
}
|
||||
Reference in New Issue
Block a user