JSFiddle - React, Tailwind, and code Playground

by flek

HTML

<html ng-app>
    <head>
    </head>
    <body ng-controller="Root">
        <h1>Base Angular Fiddle</h1>
        Times changed(length): {{timesChanged}}<br/>
        Times changed(equals): {{timesChangedEquality}}
        <ul>
            <li ng-repeat="name in names">{{name}}</li>
            <li><button ng-click="names.push('another name')">Add</button></li>
            <li><button ng-click="names[names.length-1] = ('changed')">Change</button></li>
        </ul>
    </body>
</html>

JavaScript

function Root($scope) {
    $scope.timesChanged = 0;
    $scope.timesChangedEquality = 0;
    $scope.names = ['foo', 'bar', 'baz'];
    $scope.$watch(function(){
        return hash(String($scope.names));
    }, function() {
        $scope.timesChanged++;
    });
    $scope.$watch('names', function() {
        $scope.timesChangedEquality++;
    }, true);
    
    /*
     * Fast Duff's Device
     * @author Miller Medeiros <http://millermedeiros.com> 
     * @version 0.3 (2010/08/25)
     */
    var hash = function(str){
    var hash = 0;
    var iterations = str.length;

    var i = iterations % 8;
    while (i--) {
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
    }

    i = (iterations * 0.125) ^ 0;
    while (i--) {
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
    }

    return hash;
    }
}