I don’t know if there is such a thing, but I would come up with a different solution. Let your code look something like this (pseudo code)
<ajax onResponse="{{onResponse}}" response="{{ajaxResponse}}" url="/users"></ajax>
<template repeat="{{user in ajaxResponse}}">
<span>Hello from {{user.name}}</span>
</template>
If I understood you correctly, you said that when the request is made, the template will be re-evaluated regardless of whether there were changes in the data or not.
To fix this, we can present our data in a different way, which is evaluated not by reference, but by value.
class UserListElement extends PolymerElement {
@observable List userIds = toObservable([]);
Map<int, Object> users = {};
onResponse(var response) {
users = {};
for(var user in response) {
users[user.id] = user;
if (!users.contains(user.id)) userIds.add(user.id);
}
var toRemove = userIds.where((user) => !_userData.containsKey(user.id));
for(var userId in toRemove) userIds.remove(userId);
}
}
-
<ajax onResponse="{{onResponse}}" url="/users"></ajax>
<template repeat="{{userId in users}}">
<span>Hello from {{users[userId].name}}</span>
</template>
Like I said, not verified pseudocode. But this is the only idea I can come up with.
source
share