Skip to content

Commit

Permalink
Deprecate InertiaRails.lazy prop
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Nov 8, 2024
1 parent e37de1f commit 54fbbcd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,12 @@ end
}
```

### Lazy Props
### Optional Props

On the front end, Inertia supports the concept of "partial reloads" where only the props requested are returned by the server. Sometimes, you may want to use this flow to avoid processing a particularly slow prop on the intial load. In this case, you can use Lazy props. Lazy props aren't evaluated unless they're specifically requested by name in a partial reload.
On the frontend, Inertia supports the concept of "partial reloads" where only the props requested are returned by the server. Sometimes, you may want to use this flow to avoid processing a particularly slow prop on the initial load. In this case, you can use Optional props. Optional props aren't evaluated unless they're specifically requested by name in a partial reload.

```ruby
inertia_share some_data: InertiaRails.lazy(lambda { some_very_slow_method })

# Using a Ruby block syntax
inertia_share some_data: InertiaRails.lazy { some_very_slow_method }
inertia_share some_data: InertiaRails.optional { some_very_slow_method }
```

### Routing
Expand Down Expand Up @@ -269,6 +266,14 @@ end

__Default__: `false`

#### `encrypt_history`

When enabled, you instruct Inertia to encrypt your app's history, it uses
the browser's built-in [`crypto` api](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)
to encrypt the current page's data before pushing it to the history state.

__Default__: `false`

#### `ssr_enabled` _(experimental)_

Whether to use a JavaScript server to pre-render your JavaScript pages,
Expand Down
4 changes: 4 additions & 0 deletions lib/inertia_rails/lazy_prop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class LazyProp < IgnoreOnFirstLoadProp
def initialize(value = nil, &block)
raise ArgumentError, 'You must provide either a value or a block, not both' if value && block

InertiaRails.deprecator.warn(
"`lazy` is deprecated and will be removed in InertiaRails 4.0, use `optional` instead."
)

@value = value
@block = block
end
Expand Down
12 changes: 12 additions & 0 deletions spec/inertia/lazy_prop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
RSpec.describe InertiaRails::LazyProp do
it_behaves_like 'base prop'

let(:deprecator) do
double(warn: nil).tap do |deprecator|
allow(InertiaRails).to receive(:deprecator).and_return(deprecator)
end
end

it "is deprecated" do
expect(deprecator).to receive(:warn).with("`lazy` is deprecated and will be removed in InertiaRails 4.0, use `optional` instead.")

described_class.new('value')
end

describe '#call' do
subject(:call) { prop.call(controller) }
let(:prop) { described_class.new('value') }
Expand Down

0 comments on commit 54fbbcd

Please sign in to comment.