Skip to content

export_state needs new name and format #97

Open
@catmando

Description

@catmando

the export_state macro does two things:

  1. creates a state variables that is shared by all instances of the component class.
  2. makes the state variable publicly accessible (outside the class) so you can say Foo.state and Foo.state! anywhere.

I think we deprecate this, and change it to something like this:

state :state_name, access: :read/:update { optional initializer block }

so you would say

state :foo access: :update { [] }

to create a state called foo that was shared by all components of the class, and could be read and written externally as ClassName.foo/foo! (and that is initialized to the empty array)

The reason we need to do this is this in many instances you DONT want to export the state or if you do, you only want to export the getter.

Looking for any comments, and in particular suggestions on the syntax.

state by itself is good because its short, but probably confusing but it does not emphasize the "class level" nature.

static is great but ain't ruby.

class_state or shared_state might be the way to go?

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions