Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutability and observability #114

Open
benlieb opened this issue Dec 30, 2022 · 0 comments
Open

Immutability and observability #114

benlieb opened this issue Dec 30, 2022 · 0 comments

Comments

@benlieb
Copy link

benlieb commented Dec 30, 2022

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)
      },
    }
  }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant