mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
c17a1980a2
This simplifies stores to just be storage interaction, they no longer react to events. Controllers now call services and awaits the result from the call. When the service calls are returned the database is updated. This simplifies testing dramatically, cause you know that your state is updated when returned from a call, rather than hoping the store has picked up the event (which really was a command) and reacted to it. Events are still emitted from eventStore, so other parts of the app can react to events as they're being sent out. As part of the move to services, we now also emit an application-created event when we see a new client application. Fixes: #685 Fixes: #595
59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = () => {
|
|
const _features = [];
|
|
const _archive = [];
|
|
return {
|
|
getFeature: name => {
|
|
const toggle = _features.find(f => f.name === name);
|
|
if (toggle) {
|
|
return Promise.resolve(toggle);
|
|
}
|
|
return Promise.reject(new Error('could not find toggle'));
|
|
},
|
|
hasFeature: name => {
|
|
const toggle = _features.find(f => f.name === name);
|
|
const archived = _archive.find(f => f.name === name);
|
|
if (toggle) {
|
|
return Promise.resolve({ name, archived: false });
|
|
}
|
|
if (archived) {
|
|
return Promise.resolve({ name, archived: true });
|
|
}
|
|
return Promise.reject();
|
|
},
|
|
updateFeature: updatedFeature => {
|
|
_features.splice(
|
|
_features.indexOf(f => f.name === updatedFeature.name),
|
|
1,
|
|
);
|
|
_features.push(updatedFeature);
|
|
},
|
|
getFeatures: () => Promise.resolve(_features),
|
|
createFeature: feature => _features.push(feature),
|
|
getArchivedFeatures: () => Promise.resolve(_archive),
|
|
addArchivedFeature: feature => _archive.push(feature),
|
|
reviveFeature: feature => {
|
|
const revived = _archive.find(f => f.name === feature.name);
|
|
_archive.splice(
|
|
_archive.indexOf(f => f.name === feature.name),
|
|
1,
|
|
);
|
|
_features.push(revived);
|
|
},
|
|
lastSeenToggles: (names = []) => {
|
|
names.forEach(name => {
|
|
const toggle = _features.find(f => f.name === name);
|
|
if (toggle) {
|
|
toggle.lastSeenAt = new Date();
|
|
}
|
|
});
|
|
},
|
|
dropFeatures: () => {
|
|
_features.splice(0, _features.length);
|
|
_archive.splice(0, _archive.length);
|
|
},
|
|
importFeature: feat => Promise.resolve(_features.push(feat)),
|
|
};
|
|
};
|