From fd6aac51e79238dc364a333d9d7f409092ae326d Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Sat, 2 Mar 2019 14:40:36 +0100 Subject: [PATCH] mol-plugin: Group --- src/mol-plugin/state/transforms/misc.ts | 33 +++++++++++++++++++++++++ src/mol-state/state/builder.ts | 7 ++++++ 2 files changed, 40 insertions(+) create mode 100644 src/mol-plugin/state/transforms/misc.ts diff --git a/src/mol-plugin/state/transforms/misc.ts b/src/mol-plugin/state/transforms/misc.ts new file mode 100644 index 000000000..9c8190dd1 --- /dev/null +++ b/src/mol-plugin/state/transforms/misc.ts @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { StateTransformer } from 'mol-state'; +import { shallowEqual } from 'mol-util'; +import { ParamDefinition as PD } from 'mol-util/param-definition'; +import { PluginStateObject as SO, PluginStateTransform } from '../objects'; + +export { CreateGroup }; +type CreateGroup = typeof CreateGroup +const CreateGroup = PluginStateTransform.BuiltIn({ + name: 'create-group', + display: { name: 'Parse CIF', description: 'Parse CIF from String or Binary data' }, + from: [], + to: SO.Group, + params: { + label: PD.Text('Group'), + description: PD.makeOptional(PD.Text('')) + } +})({ + apply({ params }) { + return new SO.Group({}, params); + }, + update({ oldParams, newParams, b }) { + if (shallowEqual(oldParams, newParams)) return StateTransformer.UpdateResult.Unchanged; + b.label = newParams.label; + b.description = newParams.description; + return StateTransformer.UpdateResult.Updated; + } +}); \ No newline at end of file diff --git a/src/mol-state/state/builder.ts b/src/mol-state/state/builder.ts index 824cf3561..d1e3f9d63 100644 --- a/src/mol-state/state/builder.ts +++ b/src/mol-state/state/builder.ts @@ -70,6 +70,13 @@ namespace StateBuilder { return new To(this.state, t.ref, this.root); } + /** + * A helper to greate a group-like state object and keep the current type. + */ + group<T extends StateTransformer<A, any, any>>(tr: T, params?: StateTransformer.Params<T>, options?: Partial<StateTransform.Options>, initialCellState?: Partial<StateObjectCell.State>): To<A> { + return this.apply(tr, params, options, initialCellState) as To<A>; + } + /** * Inserts a new transform that does not change the object type and move the original children to it. */ -- GitLab