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

feat($state): make state data inheritance prototypical #2279

Merged
merged 1 commit into from
Oct 2, 2015
Merged

feat($state): make state data inheritance prototypical #2279

merged 1 commit into from
Oct 2, 2015

Conversation

chrislambe
Copy link
Contributor

Modify state data inheritance to use prototypical inhertiance rather than Angular's extend method to enable more flexibility in handling state data.

Justification

I'm currently working on a project that implements Material Design via Angular Material. We've implemented a global FAB by attaching information about what the FAB should do to the state definition. For example:

angular.module('MyMaterialDesignProject')
  .config(function($stateProvider) {
    $stateProvider
      .state('foo', {
        url: '/foo',
        data: {
          primaryAction: {
            onClick: function($state) {
              $state.go('foo.bar');
            }
          }
        }
      })
      .state('foo.bar', {
        url: '/bar'
      });
  });

When we arrive at foo.bar we need to be able to tell if data.primaryAction is defined as part of the foo.bar state definition or if it's inherited. If it's inherited we (maybe) don't want to display the FAB.

Risk of breaking change

Any dev who has implemented a test to determine the availability of a data property using data.hasOwnProperty('foo') rather than something like 'foo' in data is at risk of having their app stop functioning as they expect.

@nateabele
Copy link
Contributor

@christopherthielen Obviously we'll want to use inherit() but I am fundamentally down with this. Any objection?

Modify state data inheritance to use prototypical inhertiance rather than Angular's extend method to enable more flexibility in handling state data.
@chrislambe
Copy link
Contributor Author

Switched to using inherit().

@christopherthielen
Copy link
Contributor

I totally thought we were already doing it this way, hah. 👍

@chrislambe
FYI I use data for metadata the entire tree of states cares about, but I've been plopping non-inherited metadata directly on the state declarations, e.g.,

.state('admin', {
 url: '/admin',
 dsr: true, // <- plop
 data: {
  roles: ['ADMIN']
 } 
}```

@chrislambe
Copy link
Contributor Author

@christopherthielen Oh, interesting. That's helpful, thanks!

nateabele added a commit that referenced this pull request Oct 2, 2015
feat($state): make state data inheritance prototypical
@nateabele nateabele merged commit 6f723a5 into angular-ui:master Oct 2, 2015
@chrislambe chrislambe deleted the prototypical-data-inheritance branch April 13, 2016 19:24
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

Successfully merging this pull request may close these issues.

3 participants