Fix questions: applicable mappings are now calculated dynamically; charging station theme now only shows applicable plugs based on the allowed vehicle types
This commit is contained in:
parent
bedc576313
commit
df34239256
14 changed files with 3677 additions and 3359 deletions
|
@ -68,6 +68,50 @@ export class UIEventSource<T> {
|
|||
return src
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a UIEVentSource with a list, returns a new UIEventSource which is only updated if the _contents_ of the list are different.
|
||||
* E.g.
|
||||
* const src = new UIEventSource([1,2,3])
|
||||
* const stable = UIEventSource.ListStabilized(src)
|
||||
* src.addCallback(_ => console.log("src pinged"))
|
||||
* stable.addCallback(_ => console.log("stable pinged))
|
||||
* src.setDate([...src.data])
|
||||
*
|
||||
* This will only trigger 'src pinged'
|
||||
*
|
||||
* @param src
|
||||
* @constructor
|
||||
*/
|
||||
public static ListStabilized<T>(src: UIEventSource<T[]>) : UIEventSource<T[]>{
|
||||
|
||||
const stable = new UIEventSource<T[]>(src.data)
|
||||
src.addCallback(list => {
|
||||
if(list === undefined){
|
||||
stable.setData(undefined)
|
||||
return;
|
||||
}
|
||||
const oldList = stable.data
|
||||
if(oldList === list){
|
||||
return;
|
||||
}
|
||||
if(oldList.length !== list.length){
|
||||
stable.setData(list);
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if(oldList[i] !== list[i]){
|
||||
stable.setData(list);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// No actual changes, so we don't do anything
|
||||
return;
|
||||
})
|
||||
return stable
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a callback
|
||||
*
|
||||
|
@ -88,7 +132,7 @@ export class UIEventSource<T> {
|
|||
|
||||
public addCallbackAndRun(callback: ((latestData: T) => (boolean | void | any))): UIEventSource<T> {
|
||||
const doDeleteCallback = callback(this.data);
|
||||
if (!doDeleteCallback) {
|
||||
if (doDeleteCallback !== true) {
|
||||
this.addCallback(callback);
|
||||
}
|
||||
return this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue