collective-soundworks / soundworks

Creative coding framework for distributed applications based on Web technologies.
http://soundworks.dev
BSD 3-Clause "New" or "Revised" License
114 stars 7 forks source link

stateManager.getCollection - review / generalize options #94

Open b-ma opened 3 months ago

b-ma commented 3 months ago

options could be:

Generalize existing parameter filtering feature (apply to SharedState and SharedCollection):

Allow to model some hierarchies / relationships (apply to SharedCollection):

const parent = stateManager.attach('parent');
const children = stateManager.getCollection('child', {
   constraint: values => values.parentId === parent.id
});

This could be quite simply done on the client side, just detaching early from the state if the value does not match, or even by propagating init state values in OBSERVE_NOTIFICATION to avoid additional network roundtrips.

The constraint could also be a pure facade, allowing to insert / remove a state from the collection when one of it's param changes and match the constrain... to be discussed

Maybe provide both behaviours:

Would also benefit from #93

jipodine commented 3 months ago

Why not keep the whitelist (and maybe blacklist) for the subscriptions? constraint sounds more like a requirement to me. (If constraint' is to be used, do not forget thes`.)

Is there a way to integrate that with the filtering of attributes, to get only a subset (regardless of their values)?

b-ma commented 3 months ago

filter rather than constraint

b-ma commented 1 month ago

Actually the dynamicFilter behavior is not very relevant as we already have the SharedStateCollection#filter method. This would also create problems such as how to be notified when the collection change, etc.

For now, let's just stick with something like:

stateManager.getCollection('test', {
  whitelistParams: ['a', 'b'],
  backlistParams: ['a', 'b'],
  filterStates: (currentValues) => currentValues.group === 'group-1',
});