Originally created by @tmspzz on GitHub (May 20, 2016).
Current State:
Monitors created via transaction.monitor... for transaction of type UnsafeDataTransaction do not get notified of changes until the transaction is committed.
However, they are notified if transaction.internalContext.save() is called
Proposal:
Have the option in a UnsafeDataTransaction to be notified upon context saves. Maybe in the fashion on transaction.flushesChangesImmediately = true
Originally created by @tmspzz on GitHub (May 20, 2016).
Current State:
Monitors created via `transaction.monitor...` for transaction of type `UnsafeDataTransaction` do not get notified of changes until the transaction is committed.
However, they are notified if `transaction.internalContext.save()` is called
Proposal:
Have the option in a `UnsafeDataTransaction` to be notified upon context saves. Maybe in the fashion on `transaction.flushesChangesImmediately = true`
I can't think of a reasonable timing for an auto-flush without any trigger from some function call.
It will be too heavy if each property assignment triggers one flush.
The simplest I can think is to require a call to transaction.flush() when the changes are ready to be propagated to observers.
Another solution is to wrap all changes in closures:
extensionUnsafeDataTransaction{funcflush(@noescapeclosure:()->Void){closure()self.internalContext.save()}}// ...transaction.flush{// ... make changes}
@JohnEstropia commented on GitHub (May 20, 2016):
I can't think of a reasonable timing for an auto-flush without any trigger from some function call.
It will be too heavy if each property assignment triggers one flush.
The simplest I can think is to require a call to `transaction.flush()` when the changes are ready to be propagated to observers.
``` swift
extension UnsafeDataTransaction {
func flush() {
self.internalContext.save()
}
}
```
Another solution is to wrap all changes in closures:
``` swift
extension UnsafeDataTransaction {
func flush(@noescape closure: () -> Void) {
closure()
self.internalContext.save()
}
}
// ...
transaction.flush {
// ... make changes
}
```
extension UnsafeDataTransaction {
/**
Cause the changes made in the transaction to be saved to the backing `NSMangedObjectContext`
- Attention:
Calling this method **will not commit the transaction**.
Changes will not be propagated to the `DataStack`
*/
func flush() throws {
try self.internalContext.save()
}
/**
Cause the changes made in the transaction to be saved to the backing `NSMangedObjectContext`
- Attention:
Calling this method **will not commit the transaction**.
Changes will not be propagated to the `DataStack`
*/
func flushing(@noescape closure: () throws -> Void) throws {
try closure()
try self.flush()
}
}
@tmspzz commented on GitHub (May 20, 2016):
I like the closure approach. However the scenario for that usage sometime looks like:
```
transaction.flushing {
transaction.importObject...
}
```
I would give the option for both.
```
extension UnsafeDataTransaction {
/**
Cause the changes made in the transaction to be saved to the backing `NSMangedObjectContext`
- Attention:
Calling this method **will not commit the transaction**.
Changes will not be propagated to the `DataStack`
*/
func flush() throws {
try self.internalContext.save()
}
/**
Cause the changes made in the transaction to be saved to the backing `NSMangedObjectContext`
- Attention:
Calling this method **will not commit the transaction**.
Changes will not be propagated to the `DataStack`
*/
func flushing(@noescape closure: () throws -> Void) throws {
try closure()
try self.flush()
}
}
```
@tmspzz commented on GitHub (May 23, 2016):
Was thinking maybe the first case can be made prettier:
```
transaction.flushing { flush in
flush.importObject...
}
```
```
func flushing(@noescape closure: (flush: UnsafeDataTransaction) throws -> Void) throws {
try closure()
try self.flush()
}
```
In the end I stuck the name flush, I hope you won't mind:
public func flush() throws
public func flush(@noescape closure: () throws -> Void) throws
It matches CoreStore's SQL-ish naming (begin, commit, etc) and there's really no need to give separate names for the no-closure and the closure versions.
@JohnEstropia commented on GitHub (May 23, 2016):
In the end I stuck the name `flush`, I hope you won't mind:
```
public func flush() throws
public func flush(@noescape closure: () throws -> Void) throws
```
It matches CoreStore's SQL-ish naming (begin, commit, etc) and there's really no need to give separate names for the no-closure and the closure versions.
See: https://github.com/JohnEstropia/CoreStore/commit/c15afcb381cdb46d3d85c0cd0624df8e598e4a3b
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @tmspzz on GitHub (May 20, 2016).
Current State:
Monitors created via
transaction.monitor...for transaction of typeUnsafeDataTransactiondo not get notified of changes until the transaction is committed.However, they are notified if
transaction.internalContext.save()is calledProposal:
Have the option in a
UnsafeDataTransactionto be notified upon context saves. Maybe in the fashion ontransaction.flushesChangesImmediately = true@JohnEstropia commented on GitHub (May 20, 2016):
I can't think of a reasonable timing for an auto-flush without any trigger from some function call.
It will be too heavy if each property assignment triggers one flush.
The simplest I can think is to require a call to
transaction.flush()when the changes are ready to be propagated to observers.Another solution is to wrap all changes in closures:
@tmspzz commented on GitHub (May 20, 2016):
I like the closure approach. However the scenario for that usage sometime looks like:
I would give the option for both.
@tmspzz commented on GitHub (May 23, 2016):
Was thinking maybe the first case can be made prettier:
@JohnEstropia commented on GitHub (May 23, 2016):
In the end I stuck the name
flush, I hope you won't mind:It matches CoreStore's SQL-ish naming (begin, commit, etc) and there's really no need to give separate names for the no-closure and the closure versions.
See: https://github.com/JohnEstropia/CoreStore/commit/c15afcb381cdb46d3d85c0cd0624df8e598e4a3b