Skip to content

Immutability and observability #114

Description

@benlieb

I've only played with spraypaint for a day now, but it is nearly everything I wanted in client-side modeling. Great library.

Since I do a lot of react-style UIs though, it would be really wonderful if this lib added observability (when attrs change) and immutability (as in immutable.js). That would make the circle complete for me.

So I guess this is a feature request.

Currently trying to figure out how to patch into the EventBus like I see in the source for observability:

EventBus.addEventListener(this.storeKey, this.onStoreChange())

But not successfully.

I've also implemented a super simple POC for making attr changes, but it's far from ideal:

const ApplicationRecord = SpraypaintBase.extend(
  {
    static: {
      baseUrl: window.location.origin,
      apiNamespace: "/api"
    },
    methods: {
      set: function(prop, val) {
        this[prop] = val
        this.notifyListeners()
      },

      notifyListeners: function() {
        console.log('notifying');
        this.changeListeners ||= []
        this.changeListeners.forEach(
          listener => listener(this)
        )
      },

      registerListener: function(listener) {
        this.changeListeners ||= []
        this.changeListeners.push(listener)
      },
    }
  }
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions