yapplabs / ember-buffered-proxy Goto Github PK
View Code? Open in Web Editor NEWAn Ember Proxy the enables change buffering
License: MIT License
An Ember Proxy the enables change buffering
License: MIT License
Hi! Thank you for you your awesome project.
I wonder whether i can use ember-buffered-proxy on Ember Data records.
My use case:
.rollback()
because it will revert the unsaved record to a tabula rasa state, while the user expects it to be reverted to state A.My problem is that the record in question does not store much data itself: all its data comes from related child and grandchild records.
Does this mean that i have to apply discardBufferedChanges
recursively? Is there a simpler way?
I created a proxy to an Ember Data model, and the ED model had ember-validations mixed in. I was hoping my proxy would have a .validate
method, but it didn't. Is this expected? Is there a way to bring that along as well?
Thanks for this lib, has saved me many times!
Hi!
Is it possible to get a list of which keys on the buffered proxy are dirty?
I currently have a buffered array proxy implementation that follows the current buffered object proxy API structure. Do you think that you'd be interested in a PR or should I create a separate addon for it?
@lukemelia Can we release a new version of this addon? I propose a major version bump because we have a breaking change.
Here is the comparison: v1.0.1...master
Changelog:
Hi folks. Got a small bug when upgrading my Ember app. Interestingly, this bug was attempted to be fixed previously, and that "fix" seems to now be a bug. More detail below:
When modifying a property on a buffer proxy object, via an input field, the changes should be reflected in the template.
The first character typed in to the field was reflected on the template, any after that were not.
Ember: v3.20.2
Ember Buffered Proxy: v2.0.0-beta.0
This as ok in Ember v3.17.0
which is what I am upgrading from.
I see that there was a fix here (46d00d7) and here (3f63beb) that "fixed" the same issue. The change was basically this:
- notifyPropertyChange(this, key);
+ notifyPropertyChange(content, key);
I have tested in my local code to reverse this change and it actually works.
So, maybe the bug that was originally "fixed" was actually working around a bug in Ember itself, that has since been patched, rendering the "fix" in this repo redundant.
I don't have enough context around how the notifyPropertyChange
works and what changes have been made to Ember (and Glimmer?) to diagnose this myself.
I have created 2 codesandboxes (below) that reproduce this issue. The first is the working sandbox using Ember v3.17.0
and the second where the issue is present, using Ember 3.20.2
.
Working: https://codesandbox.io/s/vibrant-browser-g4n7p
Not working: https://codesandbox.io/s/happy-wilbur-btx3x
I'm happy to submit a PR that changes this code back, however, it feels like it might be worth actually understanding the reasoning as to why the original code stopped working in the first place and why it now works. I'd need some assistance in digging in to that.
What's the appropriate way to see if a buffered proxy has changes (is dirty) from its content?
We found proxy.hasBufferedChanges
here - is that public?
I feel like I'm typing "buffered" a lot and it feels redundant. Would the maintainers be open to shortening the method names?
From this:
buffer.discardBufferedChanges()
buffer.applyBufferedChanges();
buffer.get('hasBufferedChanges');
To this:
buffer.discardChanges()
buffer.applyChanges();
buffer.get('hasChanges');
I am facing an issue with buffered proxy with ember 3.6+. setUnknownProperty
function is what is causing this issue. Anyone else is facing any issue in this function ? It basically sets hasBufferedChanges
to true when it is supposed to be false.
I just implemented ember-buffered-proxy
to make an edit modal edit independently of the main page. I took some notes here that might help someone else. Or maybe even turned into an example/guide?
https://gist.github.com/caseywatts/6b0ecf13da4fea3949ff92551eb921e0
I listened to the frontside podcast (June) and learned that ObjectPoxy's are on the way out of Ember.
Even after the move from two way bindings to one way bindings, buffered proxy's are still useful
(e.g. to collect form data, which will eventually be transferred to a model).
How will this affect the ember-buffered-proxy project?
Relying on ember-buffered-proxy
to detect model changes has the drawback that comparisons are strict, and therefore a simple type change is captured by the buffer.
When using an HTML input
to edit the value of a model property that is defined as a number, the value is returned from the input as a string. This results in hasChanges
being true, when in fact the value has not changed, only the type has changed.
Ember serializers will convert this value back to a number based on the model definition when posted to the server, but the buffer recognizing this as a change means it cannot be relied upon for something like enabling/disabling a Save button in a form.
I'm not sure whether the solution would be to do only value comparisons in ember-buffered-proxy
or to support a flag that would allow value only comparisons.
How would you use buffered proxy for nested properties e.g. post.author.name
and an array of objects e.g. post.tags[{name: 'tag one'}, {name: 'tag two'}]
For the array i'm cloning the array and setting the property, which updates hasChanges
.
There seems to be no proxy for post.author.name
so the changes are applied to the model. Would i need to create a new proxy for post.author
?
We use this addon a lot in our project. Thanks for making it happen ๐
When upgrading to Ember 3.13 we realized that buffered properties are not getting refreshed on views when we modify them.
Consider example:
// application.js
let user = {
firstName: 'stefan',
email: '[email protected]'
};
let buffer = BufferedProxy.create({
content: user
});
When we change the value in input
then the value in the <div>
should be updated. It works properly on Ember 3.12 but fails on Ember 3.13.
Something had to change around tracked properties IMO but I'm not sure exactly what.
Anyway, the fix is really a one-liner. But it would be great to understand the impact of this change.
I use BufferedProxy on my forms for buffering changes before save and want to use ember-cp-validations https://github.com/offirgolan/ember-cp-validations for validating them.
I can't use model validation, because values are setting to buffer first, so I trying to extend BufferedProxy object with Validations.
import BufferedProxy from 'ember-buffered-proxy/proxy';
const Validations = buildValidations({...});
let UserBuffer = BufferedProxy.extend(Validations);
From their doc:
"To lookup validators, container access is required which can cause an issue with Ember.Object creation if the object is statically imported."
So I need to pass a container as first parameter.
UserBuffer.create(
getOwner(this).ownerInjection(),
{ content: this.get('user') } // user is model object
);
It works well with normal ObjectProxy
let UserBuffer = Ember.ObjectProxy.extend(Validations);
but don't with BufferedProxy
let UserBuffer = BufferedProxy.extend(Validations);
Guys from ember-cp-validations advised me to ask you
adopted-ember-addons/ember-cp-validations#135
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.