<commit_before>/**
 * @license
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Load this file and make your Angular module depend on the 'foam' module to
// get foam-view and foam-repeat directives in your code.
//
// Correct load order is Angular 1.5 and FOAM 2 (either order), this library,
// then your application module that uses Angular and this library.

/* globals angular: false */
angular.module('foam', [ 'ngMaterial' ]).directive('foamView', function() {
  return {
    restrict: 'A',
    scope: {
      // TODO: Make these one-way reactive bindings, probably.
      // Except for "as", that should just be a string.
      key: '<foamView',
      dao: '<foamDao',
      as: '@foamAs',
      delay: '@foamDelay'
    },
    priority: 2000,
    transclude: 'element',
    link: function($scope, element, attrs, controllers, transcludeFn) {
      var obj;
      var innerScope;

      var delay = typeof $scope.delay === 'undefined' ? 100 : $scope.delay;
      var as = $scope.as || 'object';

      // Subscription to changes inside the DAO.
      var daoSub;
      // Subscription to changes on the cloned object.
      var objSub;

      // Look up our FOAM object on the DAO.
      function initialStart() {
        $scope.dao.find($scope.key).then(hookUpObject);
        daoSub && daoSub.destroy();
        daoSub = $scope.dao.on.sub(function(sub, _, operation, obj) {
          if ( operation === 'reset' ) {
            initialStart();
          } else if ( obj.id === $scope.key ) {
            hookUpObject(obj);
          }
        });
      }

      $scope.$watch('key', initialStart);
      $scope.$watch('dao', initialStart);

      function hookUpObject(o) {
        innerScope[as] = obj = o.clone();
        innerScope.$apply();

        objSub && objSub.destroy();<commit_msg>Angular: React to foam-as changing correctly<commit_after>/**
 * @license
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Load this file and make your Angular module depend on the 'foam' module to
// get foam-view and foam-repeat directives in your code.
//
// Correct load order is Angular 1.5 and FOAM 2 (either order), this library,
// then your application module that uses Angular and this library.

/* globals angular: false */
angular.module('foam', [ 'ngMaterial' ]).directive('foamView', function() {
  return {
    restrict: 'A',
    scope: {
      // TODO: Make these one-way reactive bindings, probably.
      // Except for "as", that should just be a string.
      key: '=foamView',
      dao: '<foamDao',
      as: '@foamAs',
      delay: '@foamDelay'
    },
    priority: 2000,
    transclude: 'element',
    link: function($scope, element, attrs, controllers, transcludeFn) {
      var obj;
      var innerScope;

      var delay = typeof $scope.delay === 'undefined' ? 100 : $scope.delay;
      var as = $scope.as || 'object';

      // Subscription to changes inside the DAO.
      var daoSub;
      // Subscription to changes on the cloned object.
      var objSub;

      // Look up our FOAM object on the DAO.
      function initialStart() {
        $scope.dao.find($scope.key).then(hookUpObject);
        daoSub && daoSub.destroy();
        daoSub = $scope.dao.on.sub(function(sub, _, operation, obj) {
          if ( operation === 'reset' ) {
            initialStart();
          } else if ( obj.id === $scope.key ) {
            hookUpObject(obj);
          }
        });

        innerScope.$watch(as, function(nu, old) {
          if ( nu && nu.id !== (old && old.id) ) {
            $scope.key = nu.id;
          }
        });
      }

      $scope.$watch('key', initialStart);
      $scope.$watch('dao', initialStart);

      function hookUpObject(o) {
        innerScope[as] = obj = o.clone();
        innerScope.$apply();

        objSub && objSub.destroy();
{'fraction_non_alphanumeric': 0.1215749949259184, 'fraction_numerical': 0.007306677491374061, 'mean_word_length': 2.52755905511811, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2722857', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1384, 'n_words': 508}