Giter Site home page Giter Site logo

ember-buffered-proxy's People

Contributors

acorncom avatar blimmer avatar brandonparsons avatar charlesfries avatar dependabot[bot] avatar ember-tomster avatar enspandi avatar fsmanuel avatar lukemelia avatar marcioj avatar miguelcobain avatar mitchlloyd avatar raycohen avatar rondale-sc avatar samselikoff avatar stefanpenner avatar thoov avatar tniezurawski avatar turbo87 avatar xomaczar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-buffered-proxy's Issues

Provide example of using bufferedProxy on records with relationships

Hi! Thank you for you your awesome project.

I wonder whether i can use ember-buffered-proxy on Ember Data records.

My use case:

  1. A record is created clientside when a user visits the route. The record will eventually be persisted to the backend, but during this use case it does not.
  2. The user opens a modal dialog with an edit form, edits the record and presses OK in the form to close the dialog. From the user perspective, he has kinda saved his edits, and the record is now in state A.
  3. The user can open the form and edit the record again. The record is now is in state B. If he messes up, he should be able to discard his edits by pressing Cancel instead of OK. I cannot use .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?

what gets referenced in the proxy?

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!

List of Changed Keys

Hi!

Is it possible to get a list of which keys on the buffered proxy are dirty?

Buffered Array Proxy

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?

Release new version: 2.0.0

@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:

  • [Breaking Change] Drop support for Ember < 3.8
  • [Maintanance] Bump Ember from 2.15 to 3.14
  • [Bug fix] Buffered properties are not refreshing on Ember 3.13 (#48)

Changes to buffered proxy not appearing in template

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:

What I expected to see

When modifying a property on a buffer proxy object, via an input field, the changes should be reflected in the template.

What I saw

The first character typed in to the field was reflected on the template, any after that were not.

Software versions

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.

Supporting info

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.

/cc @tniezurawski @lukemelia

Check if proxy has changes?

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?

Shorten method names?

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');

Buffered Proxy with Ember 3.6+

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.

The future of buffered-proxy

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?

Prevent buffering of type changes

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.

Manage nested properties, arrays

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?

Buffered properties are not refreshing on Ember 3.13

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
});
{{!-- application.hbs --}}

<div>{{buffer.firstName}}</div>

{{input value=buffer.firstName onChange=(action (mut buffer.firstName))}}

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.

Using with ember-cp-validations

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.