mirror of
https://github.com/flarum/core.git
synced 2025-07-27 11:40:24 +02:00
Replace Ember app with Mithril app
This commit is contained in:
22
js/lib/utils/computed.js
Normal file
22
js/lib/utils/computed.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export default function computed() {
|
||||
var args = [].slice.apply(arguments);
|
||||
var keys = args.slice(0, -1);
|
||||
var compute = args.slice(-1)[0];
|
||||
|
||||
var values = {};
|
||||
var computed;
|
||||
return function() {
|
||||
var recompute = false;
|
||||
keys.forEach(function(key) {
|
||||
var value = typeof this[key] === 'function' ? this[key]() : this[key];
|
||||
if (values[key] !== value) {
|
||||
recompute = true;
|
||||
values[key] = value;
|
||||
}
|
||||
}.bind(this));
|
||||
if (recompute) {
|
||||
computed = compute.apply(this, keys.map((key) => values[key]));
|
||||
}
|
||||
return computed;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user