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

Parcel support #46

Closed
purcebr opened this issue Jun 14, 2020 · 6 comments
Closed

Parcel support #46

purcebr opened this issue Jun 14, 2020 · 6 comments

Comments

@purcebr
Copy link

purcebr commented Jun 14, 2020

Hi!
Is there plan for supporting using parcels in the single-spa-angularjs package? I see how it might be done, but it doesn't look like it's implemented in this package yet?

@joeldenning
Copy link
Member

You can always use parcels by calling the mountParcel function manually, but we also try to provide framework-specific components/directives that do that for you. You are right that we do not have a directive/component for AngularJS yet. Do you have interest in submitting a pull request adding support? If so, I can guide you on an implementation approach.

@purcebr
Copy link
Author

purcebr commented Jun 15, 2020

Yes! I would very much be interested in adding support. As you recommend, I'll work on integrating it into my app with mountParcel function to get familiar with the concepts.

@joeldenning
Copy link
Member

I think that an element directive would make the most sense, since they work in all versions of AngularJS, whereas AngularJS components only are supported in newer versions.

I think that modifying the bootstrap function might make the most sense:

function bootstrap(opts) {
return Promise.resolve();
}

Here's a rough idea of what the implementation could look like

function bootstrap(opts, applicationProps) {
  return Promise.resolve().then(() => {
    const module = opts.angular.module('single-spa-angularjs', [])
    module.directive('singleSpaParcel', {
      restrict: 'E',
      template: "<div></div>",
      controller: ['$scope', '$element', function ($scope, $element) {
        const parcel = applicationProps.mountParcel($scope.parcelConfig, getParcelProps())

        $scope.$on('$destroy', () => {
          parcel.unmount()
        })

        $scope.$watch('props', () => {
          parcel.update(getParcelProps())
        })

        function getParcelProps() {
          return {
           domElement: $element[0],
            ...scope.props
          }
        }
      })]
    })
  })
}

This is a rough implementation and my AngularJS is a bit rusty, so I might be missing something.

@joeldenning
Copy link
Member

A couple other notes from this:

  1. We'd need to update teh documentation to instruct people to add the single-spa-angularjs module as an AngularJS dependency to their main module.
  2. It is possible that calling opts.angular.module('single-spa-angularjs', []) inside of bootstrap is too late for Angular dependency injection to work. If that's the case, we'd want to move it into the singleSpaAngularJs function that creates the lifecycles. Doing it synchronously there would be early enough for most setups to work well.

@joeldenning
Copy link
Member

I've implemented this in #55

@joeldenning
Copy link
Member

This is released in https://github.com/single-spa/single-spa-angularjs/releases/tag/v4.2.0

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

2 participants