gruntjs/grunt — pull request #602 by mehcode (2013-01-02 18:32:54+00:00)
Title: Proof of concept for only 'compiling what is needed' (gh-593)

This is a proof-of-concept implementation of what I discussed on #593.

This adds the library to the `grunt.util` namespace (as well as a helper in the `grunt.file` namespace).

Now, from inside a task; one may filter oneself using something like the following:
```javascript
var exists = grunt.file.exists(dest);
var changed = grunt.util._.all(files, function(file) {
return grunt.file.state(file, 'grunt-contrib-coffee') !== 'ready';
});

if (!exists || changed) {
// Perform task ...
}
```

is a working implementation of the above.

The `grunt.file.state` (delegates to `grunt.util.witness.state`) takes two parameters. The file path and an optional context. The context is there so that each context can be informed about a state change once.

```javascript
// Now if we assume we modified the content again. Notice how 'apple' and
// 'orange' only get notified about the changed event once.

witness.state('src/one.coffee', 'apple'); // == 'changed'
witness.state('src/one.coffee', 'orange'); // == 'changed'
witness.state('src/one.coffee', 'apple'); // == 'ready'
witness.state('src/one.coffee', 'orange'); // == 'ready'
```

Thoughts, concerns, etc.?

---

The next step after this for the library is to integrate into grunt-contrib-watch so its only notified when necessary.