Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources Middleware Caching and Api Updates #877

Merged
merged 20 commits into from
Jan 20, 2021

Conversation

agubler
Copy link
Member

@agubler agubler commented Jan 17, 2021

Type: feature

The following has been addressed in the PR:

Description:

As part of the Dojo 8, the dojo resources middleware has been overhauled in order to support upcoming functionality such as creating and editing resources, custom resource apis and caching options.

Template Api Changes

Template are now required to specify an idKey to indicate which property of the data is considered the unique id. This is to enable future work such as save/create.

Templates that require options (previously called initOptions) are not defined as a function with the options as the single parameter. These options are passed by the user when the template is used.

template({ data: [] })

The result can be used with the resource api or with the resource widget property.

Resource Api Changes

These changes have refined the API based on using resources, providing fine grained meta details and control into individual item states.

  • createOptions: Update the createOption API has been updated to accept a setter to manage option updates
const options = createOptions((curr, next) => ({ ...curr, ...next }));
  • find: The find API has been removed in favour of a get API that can return items that are loaded in memory. For resources that are in memory the get API will be the equivilent to using the find API for resources where the entire dataset isn't loaded it's unlikely that remote APIs would have support to return the needed information for find to work successfully and tend fallback to searching in memory (aka using get)
  • meta: The meta API has been removed in favour of a meta flag that can be passed to the get and getOrRead APIs
getOrRead(template, options(), true);
get(template, options(), true);
  • isLoading: The isLoading API has been moved to be part of the meta information that is returned using the meta flag with get and getOrSet

Resource Property Api Change

The resource property has been updated to include to two shorthand variations

Using the default template

Data can be passed in an object to the resource property that will use the default template by default:

resource={{ data: [{ foo: 'bar' ], id: 'example', idKey: 'foo' }}

Or the result of a template can be passed:

resource={template({ data: [{ foo: 'bar' ], id: 'example'  })}

The caveat is that the template/data must match requirements of the widget, when transforms or options need to be passed the resource middleware needs to be used.

Todo

  • Update all the resource documentation

Resolves #875
Resolves #876
Resolves #849

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 17, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 24809c0:

Sandbox Source
dojo/dojo-codesandbox-template Configuration

@codecov
Copy link

codecov bot commented Jan 17, 2021

Codecov Report

Merging #877 (24809c0) into master (9bbcff9) will decrease coverage by 0.13%.
The diff coverage is 97.35%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #877      +/-   ##
==========================================
- Coverage   94.72%   94.58%   -0.14%     
==========================================
  Files         127      127              
  Lines        8130     7959     -171     
  Branches     1894     1859      -35     
==========================================
- Hits         7701     7528     -173     
- Misses        429      431       +2     
Impacted Files Coverage Δ
src/core/middleware/resources.ts 97.29% <97.35%> (-1.32%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da85f2e...24809c0. Read the comment docs.

@agubler agubler merged commit 820d3bc into dojo:master Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants