2018-03-31 12:55:00 +02:00
|
|
|
import create from './create';
|
2018-04-02 12:50:40 +02:00
|
|
|
import follow from './follow';
|
2018-04-03 09:33:16 +02:00
|
|
|
import undo from './undo';
|
2018-03-31 12:55:00 +02:00
|
|
|
import createObject from '../create';
|
2018-04-03 13:09:26 +02:00
|
|
|
import Resolver from '../resolver';
|
2018-03-31 12:55:00 +02:00
|
|
|
|
2018-04-03 13:09:26 +02:00
|
|
|
export default (resolver: Resolver, actor, value, distribute?: boolean) => {
|
2018-04-03 09:33:16 +02:00
|
|
|
return resolver.resolve(value).then(resolved => Promise.all(resolved.map(async promisedResult => {
|
|
|
|
const result = await promisedResult;
|
|
|
|
const created = await (await createObject(result.resolver, actor, [result.object], distribute))[0];
|
2018-03-31 12:55:00 +02:00
|
|
|
|
|
|
|
if (created !== null) {
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
|
2018-04-03 09:33:16 +02:00
|
|
|
switch (result.object.type) {
|
2018-03-31 12:55:00 +02:00
|
|
|
case 'Create':
|
2018-04-03 09:33:16 +02:00
|
|
|
return create(result.resolver, actor, result.object, distribute);
|
2018-03-31 12:55:00 +02:00
|
|
|
|
2018-04-02 12:50:40 +02:00
|
|
|
case 'Follow':
|
2018-04-03 09:33:16 +02:00
|
|
|
return follow(result.resolver, actor, result.object, distribute);
|
|
|
|
|
|
|
|
case 'Undo':
|
|
|
|
return undo(result.resolver, actor, result.object);
|
2018-04-02 12:50:40 +02:00
|
|
|
|
2018-03-31 12:55:00 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
})));
|
2018-04-01 14:17:46 +02:00
|
|
|
};
|